jimweirich/rspec-given

And doesn't give good output

hoguej opened this issue · 3 comments

When you use Then,Then,Then

You get an output line that is either red or green for each one.

When you use Then,And,And, you only get output for the first line, with the whole test succeeding or failing. You get more detail later on, but it'd be nice to have fast tests and verbose output for each test.

Should And spit out a red/green pass status? (asking before I attempt to submit a patch that would be rejected.) Is there a good reason that it doesn't do this already?

Then blocks are essentially translated into RSpec "it" blocks. Each block runs independently of the other blocks and is not effected by the success and failure of any other block.

Using:

Then { a.should == b }
And { c.should == d }

is essentially equivalent to:

it "..." do
  a.should == b
  c.should == d
end

in order to take advantage of the common setup. However, the downside is that the first assertion to fail causes any following assertions to not be run.

This is pretty fundamental to the structure of RSpec and I'm not aware of any easy way around this without delving deep into RSpec internals.

However, I'd be interested hearing possible solutions or patches in this area.

Hey @searls -- in case it's useful:

In rspec/rspec-core#756, @tovodeverett posted code for a nullipotent_tests block that lets you group a bunch of it blocks so that they share the same before(:each) setup

before(:each) { some_time_consuming_setup }
nullipotent_tests do
  it { should be_kind_of(SomeClass) }
  it { should == foo }
  . . .
end

but still pass/fail/report as separate tests. He originally did it for rspec 2, and recently updated it for rspec 3.

Maybe his approach could be used to translate

Then { a.should == b }
And { c.should == d }

into the equivalent of

nullipotent_tests do
  it { a.should == b }
  it { c.should == d }
end

I haven't grokked how either nullipotent_tests nor rspec-given do their magic, so I have no idea if they are or could be compatible. (Or maybe @tovodeverett could release his code as a separate rspec extension gem, which rspec-given could depend on and use?)

Opened this as an issue in the new repo: rspec-given#4