Outline of Rspec

xiaoxiao2026-04-11  3

1. Describe block describe "describes" do before(:each) do this will execute every time end it “it describes” do should should_not end end 2. Should and should_not method receiver.should(matcher) # the simplest example # Passes if matcher.matches?(receiver) receiver.should == expected #any value # Passes if (receiver == expected) receiver.should === expected #any value # Passes if (receiver === expected) receiver.should =~ regexp # Passes if (receiver =~ regexp) alse can use target.should be_true target.should be_false target.should be_nil target.should_not be_nil 3.should be_a_kind_of(Fixnum) 3.should be_an_instance_of(Fixnum) {:foo => “foo”}.should have_key(:foo) [1, 2, 3].should include(1) [1, 2, 3].should have(3).items 3. Shared Behaviors • before(:all) • before(:each) • after(:each) • after(:all) describe “people in general” before(:each) do puts “shared before()” end after(:each) do puts “shared after()” end ... end describe Teacher do before(:each) do puts “teacher before()” @person = Teacher.new(“Ms. Smith”, 30, 50000) end after(:each) do puts “teacher after()” end it_should_behave_like “people in general” ... end it_should_behave_like “people in general” can shared methods in people in general. Cool! 4. RSpec’s Mocks and Stubs Mock Objects echo.should_receive(:sound).with(“hey”).and_return(“hey”) Stub Objects yodeler = stub(‘yodeler’, :yodels? => true) 5. Running Specs $ spec spec/models/credit_card_spec.rb $ spec -fs spec/models/credit_card_spec.rb $ spec -fr spec/models/authorization_spec.rb 6. The RSpec on Rails Plugin $ script/generate rspec $ script/generate rspec_model Schedule name:string 相关资源:敏捷开发V1.0.pptx
转载请注明原文地址: https://www.6miu.com/read-5047188.html

最新回复(0)