= Greeter.new assert_equal 'Hello, world!', greeter.say end end describe Greeter do it 'says "Hello, world!"' do greeter = Greeter.new expect(greeter.say).to eq 'Hello, world!' end end ↑ xUnitܗࣜ ↑ Specܗࣜ
world!"' do greeter = Greeter.new greeter.say.must_equal 'Hello, world!' end end describe Greeter do it 'says "Hello, world!"' do greeter = Greeter.new expect(greeter.say).to eq 'Hello, world!' end end ↑ RSpec ʹͦͬ͘Γʂʂ
end describe '#greet' do before do puts 'Test start in #greet.' end let(:user) { User.new(name: 'ͨΖ͏', age: age) } subject { user.greet } context '12ࡀҎԼͷ߹' do let(:age) { 12 } it { is_expected.to eq '΅ͨ͘Ζ͏ͩΑɻ' } end context '13ࡀҎ্ͷ߹' do let(:age) { 13 } it { is_expected.to eq 'ͨΖ͏Ͱ͢ɻ' } end end end ϒϩοΫͰάϧʔϓԽ (ߏԽ)
start.' end end module CommonMethods def setup super puts 'Test start in #greet.' @user = User.new(name: 'ͨΖ͏', age: @age) end end class UserTestWhenUnder12 < UserTest prepend CommonMethods def setup super @age = 12 end def test_greet assert_equal '΅ͨ͘Ζ͏ͩΑɻ', @user.greet end end class UserTestWhenAbove13 < UserTest # ͭͮ͘… ܧঝͨ͠Γɺ Ϟδϡʔϧ࡞ͬͨΓɺ prepend ͨ͠Γ super ݺΜͩΓ…
end def test_greet puts 'Test start in #greet.' user = User.new(name: 'ͨΖ͏', age: 12) assert_equal '΅ͨ͘Ζ͏ͩΑɻ', user.greet user = User.new(name: 'ͨΖ͏', age: 13) assert_equal 'ͨΖ͏Ͱ͢ɻ', user.greet end end ͥΜͿϑϥοτͰ͑͑Μ