Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix a test that failed when rspec 2 was used #118

Merged
merged 1 commit into from

4 participants

@indrekj

RSpec1: spec spec => Everything OK
RSpec2: rspec spec =>

  1) Virtus::InstanceMethods#initialize with an argument that responds to #to_hash sets attributes
     Failure/Error: subject.name.should be(name)

       expected #<RSpec::Mocks::Mock:18872480> => #<RSpec::Mocks::Mock:0x11ff8a0 @name="name">
            got #<String:18867120> => "#[RSpec::Mocks::Mock:0x11ff8a0 @name=\"name\"]"

       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       'actual.should eq(expected)' if you don't care about
       object identity in this example.


       Diff:
       @@ -1,2 +1,2 @@
       -#<RSpec::Mocks::Mock:0x11ff8a0 @name="name">
       +"#[RSpec::Mocks::Mock:0x11ff8a0 @name=\"name\"]"

I wasn't 100% sure what was exactly tested here. I tried to change it to as close to the test name as possible. Now it passes with both rspec versions.

@greyblake

Looks similar: #110
Guys do not use Rspec2 since they rely on mutant.

@solnic
Owner

Small correction - we rely on heckle which requires rspec1 :) Mutant will work with rspec2 so when it's ready we'll upgrade to rspec2.

@greyblake

I think this pull request has a sense since it doesn't break anything (unlike my one) and make spec easier to understand.

@mbj
Collaborator
mbj commented

@solnic Mutant will work with any test framework as long as a framework specific killer can be written. See the current rspec2 killer.

@solnic solnic merged commit 0bd923a into solnic:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 1, 2012
  1. @indrekj
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 5 deletions.
  1. +11 −5 spec/unit/virtus/instance_methods/initialize_spec.rb
View
16 spec/unit/virtus/instance_methods/initialize_spec.rb
@@ -25,16 +25,22 @@
end
context 'with an argument that responds to #to_hash' do
- subject { described_class.new(:name => name) }
-
- let(:name) { stub('name') }
+ subject { described_class.new(attributes) }
+
+ let(:attributes) do
+ Class.new do
+ def to_hash
+ {:name => 'John'}
+ end
+ end.new
+ end
it 'sets attributes' do
- subject.name.should be(name)
+ subject.name.should == 'John'
end
end
- context' with an argument that does not respond to #to_hash' do
+ context 'with an argument that does not respond to #to_hash' do
subject { described_class.new(Object.new) }
specify { expect { subject }.to raise_error(NoMethodError) }
Something went wrong with that request. Please try again.