Closed idrozd closed 11 years ago
How are you getting these? When I use -fdoc, I get the Then { ... } code, not what you show. And I don't see the And clauses in the output at all.
Maybe a simple example spec file and the command you use to run it would be helpful here.
rspec -fdoc spec/lib/eai_spec.rb
...
Errno::ECONNREFUSED causes signature to be saved with E status
should be persisted
...
here is the corresponding spec snippet; Not sure if this could actually help you )
...
Given!(:request) { request_stub.to_return(response) }
When(:request_attempt) { signature.send_to_EAI }
Invariant { expect(request).to have_been_made.once }
shared_examples 'it handles response' do
describe 'handled cases' do
Invariant { expect(signature).to be_persisted }
[SocketError, Errno::ECONNREFUSED].each do |exception|
describe "#{exception} causes signature to be saved with E status" do
Given!(:request) { request_stub.to_raise(exception) }
Then { signature.status == Signature::STATUS_ERROR }
end
end
If I put should instead of a natural assertion to Then, I get it`s output:
SocketError causes signature to be saved with E status
should eq "E"
[SocketError, Errno::ECONNREFUSED].each do |exception|
describe "#{exception} causes signature to be saved with E status" do
Given!(:request) { request_stub.to_raise(exception) }
Then { signature.status.should eq Signature::STATUS_ERROR }
end
end
Although it`s only one example, actually all of them behave this way.
Whole file is huge, and I probably can`t show it in public
Rails is 3.1.3 (don`t ask), rspec is 2.13.0, rspec-given is 2.4.3
Actually, this could be result of me bringing all the shiny stuff altogether. It`s my first try with rspec-given (and I really enjoyed it)
I also have rspec-steps in Gemfile, and you can see that natural assertions are on, and there are couple of Invariant
So, Then clauses are actually supposed to be pasted to doc output as plain code? That would completely suite me )
I get this:
$ rspec -fd xx_spec.rb
Fake Example
specific
behaves like it handles response
handled cases
SocketError causes signature to be saved with E status
Then { signature.status == Signature::STATUS_ERROR }
Errno::ECONNREFUSED causes signature to be saved with E status
Then { signature.status == Signature::STATUS_ERROR }
Finished in 0.00277 seconds
2 examples, 0 failures
$
with this spec file (similar to yours, but with modifications to let it run):
require 'rspec/given'
class Signature
def persisted?
true
end
def status
nil
end
STATUS_ERROR = 0
end
def signature
Signature.new
end
describe "Fake Example" do
Given!(:request) { request_stub.to_return(response) }
When(:request_attempt) { signature.send_to_EAI }
Invariant { expect(request).to_not be_nil }
shared_examples 'it handles response' do
describe 'handled cases' do
Invariant { expect(signature).to be_persisted }
[SocketError, Errno::ECONNREFUSED].each do |exception|
describe "#{exception} causes signature to be saved with E status" do
Given!(:request) { request_stub.to_raise(exception) }
Then { signature.status == Signature::STATUS_ERROR }
end
end
end
end
describe "specific" do
Given(:request_stub) { mock(to_raise: mock(:persisted? => true)) }
it_behaves_like "it handles response"
end
end
Hush. So embarassing )) I`ll try to investigate it on my own on this weekend. Will let you know if find anything.
Thank you a lot for your time.
This great rspec feature bugs me when using rspec-given:
I`ve failed to find an straightforward way to disable it Even more, these "should be persisted" statements will be something else, if you put some other matcher last e.g. if in my example I would have last And with
I would have
How do you handle it?