Created
March 6, 2011 13:32
-
-
Save niku/857289 to your computer and use it in GitHub Desktop.
How do I use expect{}.to change().from().to() ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
class Foo | |
attr_reader :ary | |
def initialize | |
@ary = [] | |
@num = 0 | |
end | |
def update | |
@ary << @num | |
@num += 1 | |
end | |
end | |
describe Foo do | |
describe "#update" do | |
context 'when first update' do | |
subject{ Foo.new } | |
it do | |
expect{ subject.update }.to change(subject, :ary).from([]).to([0]) | |
end | |
end | |
end | |
end | |
# result this | |
# /Users/niku/junk/2011/03% rspec --version | |
# 2.5.1 | |
# /Users/niku/junk/2011/03% rspec --color --format documentation foo.rb | |
# | |
# Foo | |
# #update | |
# when first update | |
# should change #ary (FAILED - 1) | |
# | |
# Failures: | |
# | |
# 1) Foo#update when first update | |
# Failure/Error: expect{ subject.update }.to change(subject, :ary).from([]).to([0]) | |
# ary should have initially been [], but was [0] | |
# # ./foo.rb:20:in `block (4 levels) in <top (required)>' | |
# | |
# Finished in 0.00066 seconds | |
# 1 example, 1 failure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment