[ rspec ] expect

expect eq

expect{assign(:classAttribute)}.to eq(whatever_param)

expect{assign(:classAttribute).whatever}.to eq(whatever_param)

NOTE : assign = access class attribute of the controller

change matcher

syntax

expect do

# do_something

end.to change(object, :attribute)

example

expect do
post :create, create_attributes
end.to change(Model, :count).by(-1)

ref : https://forum.shakacode.com/t/understanding-rspec-expect-and-change-syntax-in-the-context-of-ruby/219

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s