Skip to content

Instantly share code, notes, and snippets.

@passalini
Created November 26, 2013 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passalini/7662630 to your computer and use it in GitHub Desktop.
Save passalini/7662630 to your computer and use it in GitHub Desktop.
Multiple assertions with rspec change
class Foo
attr_reader :bar, :buzz
def initialize
@bar = 1
@buzz = 1
end
def add
@bar += 1
@buzz += 9
end
end
require './foo.rb'
describe Foo do
context 'using lambda' do
before do
@foo = Foo.new
@foo_add = -> { @foo.add }
end
it { expect { @foo_add.call }.to change(@foo, :bar).from(1).to(2) }
it { expect { @foo_add.call }.to change(@foo, :buzz).by(9) }
end
context 'without lambda' do
before do
@foo = Foo.new
end
it 'should change foo by 1 and buzz by 9' do
expect { @foo.add }.to change(@foo, :bar).from(1).to(2) &&
change(@foo, :buzz).by(9)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment