Outline of Rspec

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值