jimweirich / rspec-given

Given/When/Then keywords for RSpec Specifications
https://github.com/jimweirich/rspec-given
MIT License
653 stars 61 forks source link

Funky rspec output on passing tests when required from spec_helper #38

Closed olerass closed 10 years ago

olerass commented 10 years ago

In a project with the following structure:

lib
  some_class.rb
spec
  spec_helper.rb
  unit
    some_class_spec.rb

If rspec-given is required in spec_helper then rspec -fd outputs the source file and line instead of the correct string (Then {...}) in the test case run:

SomeClass
  some test
     example at ./spec/unit/some_class_spec.rb:14
jimweirich commented 10 years ago

It sounds like source caching may be turned off. Normally it is enabled, but perhaps the spec helper file is explicitly disabling it.

Try adding the following line to the spec helper (or even your test file):

Given.source_caching_disabled = false

I could not reproduce your problem from the description (without explicitly disabling source caching).

olerass commented 10 years ago

Thanks! Given.source_caching_disabled = false in spec_helper.rb solves the problem, but I have no idea why. It would be nice if it worked out of the box though.

jimweirich commented 10 years ago

Looks like source caching is enabled if the output format requires it. Can you put the following in your spec_helper and let me know what it says...

RSpec.configure do |c|
  puts "RSPEC FORMATTERS: #{c.formatters}"
end

In the end, perhaps I should just default to always enabled rather than trying to do any fancy format sensing.

olerass commented 10 years ago

Output:

RSPEC FORMATTERS: []

Doesn't look that interesting I'm afraid :-(

jimweirich commented 10 years ago

No, actually that's quite helpful. I'm trying to guess the default value of source caching from the type of formatter used. Evidently, there are no formatters configured when given is configured, so it is guessing incorrectly.

Version 3.5.3 (just pushed) now makes a hard default to enable source caching.

Thanks for the feedback.