New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inconsistent behavior of subject when using its #819
Comments
Looks related to d177f54. Seems fixing how |
Indeed, @cupakromer is right. @exviva reported some apparent bugs with cases like: describe Person do
before { subject.age = 19 }
its(:can_vote?) { should be_true }
end In RSpec 2.12, and all previous version, this failed, because in the only example However, this is very subtle, and the original intention of So we in 2.13 we changed it (in d177f54, as @cupakromer pointed out), so that IMO, I think your spec would be much more readable, simple, clear and direct doing something like: describe "a JSON string" do
let(:expected_body) { {"a" => "b", "c" => [1,2,3]} }
subject { OpenStruct.new(:headers => [:a, :b], :body => JSON.dump(expected_body)) }
it 'allows the body to be be parsed as json' do
expect(JSON.parse(subject.body)).to eq(expected_body)
end
end (That said, I don't think I'd advocate the use of
|
Thanks for the explanation, @myronmarston. I have learned something about writing better specs instead of just being lazy about writing specs. |
@soupmatt -- my general advice is to stick to the simplest constructs you can; most of my specs are just |
When upgrading from rspec 2.12 to 2.13, I came across a change in the behavior of
its
blocks. It seems that the implied subject is different from accessing the subject by name. I see this was discussed and changed in #768 and #771, and that it is a deep and non-trivial topic, so I will leave judgement on what the correct behavior should be to those with a better understanding than mine.The following specs pass under 2.12.2 and fail under 2.13.0.
Here's a simple example that demonstrates the behavior.
Here's a example that demonstrates the use case for the 2.12.2 behavior. This is taken from actual specs in a codebase I work on at my job.
The text was updated successfully, but these errors were encountered: