rspec-core icon indicating copy to clipboard operation
rspec-core copied to clipboard

using HtmlFormatter shows RSpec's internal snippet in the report

Open jarmo opened this issue 16 years ago • 6 comments

This line will be shown as a failing line in the report: raise(RSpec::Expectations::ExpectationNotMetError.new(message))

This is one sample of such a report: http://dl.dropbox.com/u/2731643/misc/out.html

I can reproduce it like this:

# some_spec.rb 
describe "something" do 
  it "doesn't work" do 
    true.should be_false 
  end 
end 

C:\Users\jarmo\Desktop\minu\projects\Ruby\blah2>rspec some_spec.rb -f html -o out.html

This is the stack with -b:

c:/ruby/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.1/lib/rspec/expectations/fail_with.rb:29:in `fail_with' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.1/lib/rspec/expectations/handler.rb:21:in `handle_matcher' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.1/lib/rspec/expectations/extensions/kernel.rb:27:in `should' 
./some_spec.rb:3 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example.rb:47:in `instance_eval' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example.rb:47:in `run' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example.rb:86:in `call' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example.rb:86:in `with_around_hooks' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example.rb:44:in `run' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example.rb:80:in `call' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example.rb:80:in `with_pending_capture' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example.rb:79:in `catch' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example.rb:79:in `with_pending_capture' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example.rb:43:in `run' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example_group.rb:260:in `run_examples' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example_group.rb:256:in `map' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example_group.rb:256:in `run_examples' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/example_group.rb:230:in `run' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:26:in `run' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:26:in `map' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:26:in `run' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/reporter.rb:11:in `report' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:23:in `run' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run' 
c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `autorun' 
c:/Ruby/bin/rspec:19 

jarmo avatar Nov 05 '10 19:11 jarmo

It looks like format_backtrace is not called on the error's backtrace. So the backtrace is never cleaned. The SnippetExtractor takes an error in as an argument and pulls the backtrace from there. It then does not have access to the format_backtrace method. It looks like SnippetExtractor could be written to take a backtrace instead.

scrummyin avatar Jan 04 '11 20:01 scrummyin

I have a fix but it maybe messing up textmate_formatter's open file links. I do not own a mac so I am not sure what they should be like. But I have a fix for this that fixes the snippets for both textmate and html formatters.

https://github.com/scrummyin/rspec-core/commit/415fdf64e8fee26d19436e47e8a88c149bbfd307

https://github.com/scrummyin/rspec-core/commit/054e3f8d67a4577072a2a0954a1a5fba4b9bde17

scrummyin avatar Jan 05 '11 19:01 scrummyin

Any plan to merge these changes in? Are these made even into pull requests?

jarmo avatar Jan 26 '11 19:01 jarmo

These changes seem to be working for me so far. Any plan to merge into master so i could remove these lines from my gem? :)

jarmo avatar Apr 16 '11 19:04 jarmo

Hate to write just +1, but it is a major headpain, can you fix this? pretty please with sugar on?

vsalbaba avatar Jul 01 '11 09:07 vsalbaba

Sorry this took so long to get to, but it's in now and will be part of the next release.

@scrummyin, the html fix was good so I merged your commit for that. The textmate fix was close but not quite, so I ended up rolling my own on that. Let me know if you have any questions.

dchelimsky avatar Oct 01 '11 15:10 dchelimsky