[ rspec ] expect change

Syntax

expect{callFunction()}.to change{whateverParam}.by(2)

Example

class Counter
class << self
def increment
@count ||= 0
@count += 1
end

def count
@count ||= 0
end
end
end

describe Counter, "#increment" do
it "should increment the count" do
expect{Counter.increment}.to change{Counter.count}.from(0).to(1)
end

# deliberate failure
it "should increment the count by 2" do
expect{Counter.increment}.to change{Counter.count}.by(2)
end
end

ref : https://relishapp.com/rspec/rspec-expectations/v/2-0/docs/matchers/expect-change

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