STIアソシエーションの単体テストを作成する必要がある場合は、どの手順を使用する必要がありますか。私は完全に混乱しています。いくつかの提案またはいくつかのチュートリアルへのリンクを提供してください。前もって感謝します
2 に答える
1
通常、個々のクラスをテストする場合と同じように、3 つのクラスすべてをテストします。
class Person < ActiveRecord::Base
attr_reader :first_name, :last_name
def initialize
@first_name = "George"
@last_name = "Washington"
end
def formatted_name
"#{@first_name} #{@last_name}"
end
end
class Doctor < Person
def formatted_name
"Dr. #{@first_name} #{@last_name}"
end
end
class Guy < Person
def formatted_name
"Mr. #{@first_name} #{@last_name}"
end
end
describe Person do
describe "#formatted_name" do
person = Person.new
person.formatted_name.should == "George Washington"
end
end
describe Doctor do
describe "#formatted_name" do
doctor = Doctor.new
doctor.formatted_name.should == "Dr. George Washington"
end
end
describe Guy do
describe "#formatted_name" do
guy = Guy.new
guy.formatted_name.should == "Mr. George Washington"
end
end
于 2011-06-28T06:08:22.177 に答える
0
テスト ケースを作成する必要があるSTI 関係には、特別なことはまったくありません。これはフレームワークによって提供される機能であるため、フレームワークには多数のテストケースが付属しています。
構築している機能のテストケースのみを作成する必要があります。
于 2010-09-23T08:03:38.243 に答える