[rspec-devel] [ rspec-Patches-6283 ] refactoring of diff support to allow selectable formats and custom differs

noreply at rubyforge.org noreply at rubyforge.org
Mon Oct 23 20:07:35 EDT 2006


Patches item #6283, was opened at 2006-10-23 09:10
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=6283&group_id=797

Category: None
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: Lachie Cox (lachie)
>Assigned to: Aslak Hellesoy (aslak_hellesoy)
Summary: refactoring of diff support to allow selectable formats and custom differs

Initial Comment:
Supports diff formats :unified (as default) and :context using the default differ Spec::Expectations::Differs::Default.

Custom differs may be specified in the same way as custom formatters.

spec --diff                                  # unified
spec --diff unified                          # unified
spec --diff u                                # unified
spec --diff context                          # context
spec --diff c                                # context
spec --require custom --diff Custom::Differ  # loads Custom::Differ

(caveat: you can't say
  spec --diff your_spec.rb
as the option parser will eat the filename. alternatives:
  spec --diff -- your_spec.rb
  spec --diff= your_spec.rb
  spec --diff --colour your_spec.rb
  spec --diff u your_spec.rb
)

I've tried to decouple the Differ workhorse from the hook into Spec::Expectations::Should::Base as much as possible, but it still leaves a bit to be desired.

Spec::Expectations::Differs::Default is now the component with the diff/lcs dependency.

The Differ duckbill is currently:

#new(format=:unified,context_lines=3,colour=false)  # in anticipation of ansi :)
#diff_as_string(string1,string2,format=@format,context_lines=@context_lines)
#diff_as_object(object1,object2,format=@format,context_lines=@context_lines)

----------------------------------------------------------------------

>Comment By: Aslak Hellesoy (aslak_hellesoy)
Date: 2006-10-23 20:07

Message:
Applied. Awesome! It will be in 0.7.0

----------------------------------------------------------------------

Comment By: Lachie Cox (lachie)
Date: 2006-10-23 19:28

Message:
I've fixed the patch... my n00bish subversion knowledge was
the problem, sorry!

here are my notes from diff_spec.rb
# TODO Need some way of speccing diff's
Spec::Expectations::Should::Base extension
# TODO    The hook is explicitly turned off with the
RSPEC_TESTING guard under "dogfood" specs
# TODO    The code is covered because the spec running these
specs has --diff and the diff-hook switched on.

I always use rake pre_commit to see if its all good, and it was.

Its still against r954 because the work firewall blocks
subversion.

I also took the opportunity to simplify the Differ duckbill
a little:

#new(format=:unified,context_lines=3,colour=false)  # in
anticipation of ansi :)
#diff_as_string(string1,string2)
#diff_as_object(object1,object2)

----------------------------------------------------------------------

Comment By: Aslak Hellesoy (aslak_hellesoy)
Date: 2006-10-23 14:04

Message:
Great stuff. I think you forgot to attach the spec/expectations/differs/default.rb file though. It's required from option_parser.rb

Further, diff_spec.rb is now empty. What's with that? Would this still give us 100% coverage? (rake spec verify_rcov).

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=6283&group_id=797


More information about the rspec-devel mailing list