You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
response.shouldhave_tag("div","some text")person_address_tag.shouldhave_tag("input#person_address")# in a helperresponse.shouldhave_tag("div#form")dowith_tag("input#person_name[name=?]","person[name]")endresponse.shouldhave_tag("div#1")dowithout_tag("span","some text that shouldn't be there")endresponse.shouldinclude_text("This text will be in the actual string")
actual.shouldeq(expected)# passes if actual == expectedactual.should == expected# passes if actual == expectedactual.shouldeql(expected)# passes if actual.eql?(expected)
Identity
actual.shouldbe(expected)# passes if actual.equal?(expected)actual.shouldequal(expected)# passes if actual.equal?(expected)
actual.shouldbe_true# passes if actual is truthy (not nil or false)actual.shouldbe_false# passes if actual is falsy (nil or false)actual.shouldbe_nil# passes if actual is nil
Matchers to test validations and mass assignments:
describePostdoit{shouldvalidate_uniqueness_of(:title)}it{shouldvalidate_presence_of(:body).with_message(/wtf/)}it{shouldvalidate_presence_of(:title)}it{shouldvalidate_numericality_of(:user_id)}it{shouldvalidate_numericality_of(:user_id).only_integer}it{shouldvalidate_acceptance_of(:eula)}it{shouldvalidate_format_of(:name).with('12345').with_message(/is not optional/)}it{shouldvalidate_format_of(:name).not_with('12D45').with_message(/is not optional/)}it{shouldvalidate_numericality_of(:age)}it{shouldvalidate_confirmation_of(:password)}# validates_uniqueness_of requires an entry to be in the database alreadyit"validates uniqueness of title"doPost.create!(title: "My Awesome Post",body: "whatever")shouldvalidate_uniqueness_of(:title)endenddescribeUserdoit{should_notallow_value("blah").for(:email)}it{shouldallow_value("a@b.com").for(:email)}it{shouldensure_inclusion_of(:age).in_range(1..100)}it{shouldensure_exclusion_of(:age).in_range(30..60)}it{should_notallow_mass_assignment_of(:password)}endit{shouldensure_length_of(:password).is_at_least(6).is_at_most(20)}it{shouldensure_length_of(:name).is_at_least(3).with_short_message(/not long enough/)}it{shouldensure_length_of(:ssn).is_equal_to(9).with_message(/is invalid/)}
ActionController Matchers
Matchers to test common patterns:
describePostsController,"#show"docontext"for a fictional user"dobeforedoget:show,:id=>1endit{shouldassign_to(:user)}it{shouldrespond_with(:success)}it{shouldrender_template(:show)}it{should_notset_the_flash}it{shouldset_the_flash[:alert].to("Password doesn't match")}endend# other examplesit{shouldassign_to(:user)}it{should_notassign_to(:user)}it{shouldassign_to(:user).with_kind_of(User)}it{shouldassign_to(:user).with(@user)}it{shouldrender_with_layout}it{shouldrender_with_layout(:special)}it{should_notrender_with_layout}it{shouldrespond_with(:success)}it{shouldrespond_with(:redirect)}it{shouldrespond_with(:missing)}it{shouldrespond_with(:error)}it{shouldrespond_with(501)}it{shouldrespond_with_content_type(:xml)}it{shouldrespond_with_content_type(:csv)}it{shouldrespond_with_content_type(:atom)}it{shouldrespond_with_content_type(:yaml)}it{shouldrespond_with_content_type(:text)}it{shouldrespond_with_content_type('application/rss+xml')}it{shouldrespond_with_content_type(/json/)}it{shouldset_session(:message)}it{shouldset_session(:user_id).to(@user.id)}it{should_notset_session(:user_id)}it{shouldset_the_flash}it{shouldset_the_flash.to("Thank you for placing this order.")}it{shouldset_the_flash.to(/created/i)}it{shouldset_the_flash.to(/logged in/i).now}it{should_notset_the_flash}it{shouldfilter_param(:password)}