欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

rspec rspec 

程序员文章站 2024-02-22 19:10:16
...
let(:blog){Blog.new}         before(:each) do; blog=Blog.new; end
its(:title){should == nil}    @blog=Blog.new;@blog.title.should == nil
[1,2,3].should include(1)    [1,2,3].include?(1).should ==  true
{a: 1, b:2}.should have_key(:a)    {a: 1, b: 2}[:a].should_not == nil
[1,2,3].should have(3).items
blog.should be_real                blog.real?.should == true
expect{@blog.update_attribute(title: 'title')}.to change(@blog.title).from(nil).to("title")
expect{1/0}.to rails_error(ZeroDivisionError)
subject{Blog.new}; it/specify/example{should be_new_record}            
subject{Blog.new(title: 1)}; its(:title){should == 1}
@customer  = stub("customer"); @customer.stub(:name).and_return('zcy')
@customer.stub_chain(:foo, :bar, :baz).and_return("blah")
相关标签: rspec