On Oct 10, 2009, at 5:54 PM, Shot (Piotr Szotkowski) wrote:

It seems RSpec 1.2.9 is be breaking my specs in an interesting way
(both under Ruby 1.8.7 and 1.9.1). The problem may very well be in
my non-standard approach to monkey-patching core/stdlib classes,
but my approach does work with RSpec 1.2.8 and prior, as well as
in different Ruby implementations…

If you checkout my art-decomp project from
http://github.com/Chastell/art-decomp and you
‘rake spec’ the master branch under Ruby 1.9.1
or the ruby-1.8-compat branch under Ruby 1.8.7
the result should be a short, happily green run
of 114 tests – and it is if you use RSpec 1.2.8.

Unfortunately, with RSpec 1.2.9 I get the two following results (first
Ruby 1.9.1 on master, then Ruby 1.8.7 on the ruby-1.8-compat branch):


s...@devielle:~/PhD/art-decomp$ rake spec
(in /home/shot/PhD/art-decomp)
/home/shot/PhD/art-decomp/lib/set.rb:5:in `<class:Set>': undefined method `[]' for Set:Class (NoMethodError)
 from /home/shot/PhD/art-decomp/lib/set.rb:1:in `<top (required)>'
 from /home/shot/PhD/art-decomp/lib/art-decomp.rb:18:in `require'
from /home/shot/PhD/art-decomp/lib/art-decomp.rb:18:in `<top (required)>'
 from /home/shot/PhD/art-decomp/spec/spec_helper.rb:4:in `require'
from /home/shot/PhD/art-decomp/spec/spec_helper.rb:4:in `<top (required)>' from /home/shot/.gem/ruby/1.9.1/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:149:in `require' from /home/shot/.gem/ruby/1.9.1/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:149:in `block in invoke_requires' from /home/shot/.gem/ruby/1.9.1/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:148:in `each' from /home/shot/.gem/ruby/1.9.1/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:148:in `invoke_requires' from /home/shot/.gem/ruby/1.9.1/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:104:in `block in initialize' from /home/shot/.rvm/ruby-1.9.1-p243/lib/ruby/1.9.1/optparse.rb: 1271:in `call' from /home/shot/.rvm/ruby-1.9.1-p243/lib/ruby/1.9.1/optparse.rb: 1271:in `block in parse_in_order' from /home/shot/.rvm/ruby-1.9.1-p243/lib/ruby/1.9.1/optparse.rb: 1258:in `catch' from /home/shot/.rvm/ruby-1.9.1-p243/lib/ruby/1.9.1/optparse.rb: 1258:in `parse_in_order' from /home/shot/.rvm/ruby-1.9.1-p243/lib/ruby/1.9.1/optparse.rb: 1252:in `order!' from /home/shot/.gem/ruby/1.9.1/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:132:in `order!' from /home/shot/.gem/ruby/1.9.1/gems/rspec-1.2.9/lib/spec/runner.rb: 51:in `options' from /home/shot/.gem/ruby/1.9.1/gems/rspec-1.2.9/lib/spec/runner/ command_line.rb:6:in `run' from /home/shot/.gem/ruby/1.9.1/gems/rspec-1.2.9/bin/spec:5:in `<main>'
rake aborted!
Command /home/shot/.rvm/ruby-1.9.1-p243/bin/ruby -I"lib" "/home/ shot/.gem/ruby/1.9.1/gems/rspec-1.2.9/bin/spec" "spec/set_spec.rb" "spec/string_spec.rb" "spec/enumerable_spec.rb" "spec/file_spec.rb" "spec/art-decomp/graph_spec.rb" "spec/art-decomp/logging_spec.rb" "spec/art-decomp/arch_spec.rb" "spec/art-decomp/fsm_spec.rb" "spec/ art-decomp/sep_spec.rb" "spec/art-decomp/bipainter_spec.rb" "spec/ art-decomp/blanket_spec.rb" "spec/art-decomp/kiss_spec.rb" "spec/art- decomp/qv_generator/graph_colouring_spec.rb" "spec/art-decomp/ qv_generator/bipainting_spec.rb" "spec/art-decomp/qv_generator/ graph_merging_spec.rb" "spec/art-decomp/executable_spec.rb" "spec/ art-decomp/decomposer_spec.rb" "spec/art-decomp/qu_generator/ edge_labels_spec.rb" "spec/art-decomp/qu_generator/ block_table_spec.rb" "spec/art-decomp/uv_generator/ relevance_spec.rb" "spec/art-decomp/uv_generator/braindead_spec.rb" "spec/art-decomp/decomposition_spec.rb" "spec/art-decomp/b_spec.rb" "spec/integer_spec.rb" --options spec/spec.opts failed

(See full trace by running task with --trace)
s...@devielle:~/PhD/art-decomp$


s...@devielle:~/PhD/art-decomp$ rake spec
(in /home/shot/PhD/art-decomp)
./lib/set.rb:5: undefined method `[]' for Set:Class (NoMethodError)
from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/site_ruby/1.8/ rubygems/custom_require.rb:31:in `gem_original_require' from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/site_ruby/1.8/ rubygems/custom_require.rb:31:in `require'
 from ./lib/art-decomp.rb:39
from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/site_ruby/1.8/ rubygems/custom_require.rb:31:in `gem_original_require' from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/site_ruby/1.8/ rubygems/custom_require.rb:31:in `require'
 from ./spec/spec_helper.rb:4
from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/site_ruby/1.8/ rubygems/custom_require.rb:31:in `gem_original_require' from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/site_ruby/1.8/ rubygems/custom_require.rb:31:in `require' from /home/shot/.gem/ruby/1.8.7/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:149:in `invoke_requires' from /home/shot/.gem/ruby/1.8.7/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:148:in `each' from /home/shot/.gem/ruby/1.8.7/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:148:in `invoke_requires' from /home/shot/.gem/ruby/1.8.7/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:104:in `initialize' from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/1.8/optparse.rb: 1267:in `call' from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/1.8/optparse.rb: 1267:in `parse_in_order' from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/1.8/optparse.rb: 1254:in `catch' from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/1.8/optparse.rb: 1254:in `parse_in_order' from /home/shot/.rvm/ruby-1.8.7-p174/lib/ruby/1.8/optparse.rb: 1248:in `order!' from /home/shot/.gem/ruby/1.8.7/gems/rspec-1.2.9/lib/spec/runner/ option_parser.rb:132:in `order!' from /home/shot/.gem/ruby/1.8.7/gems/rspec-1.2.9/lib/spec/runner.rb: 51:in `options' from /home/shot/.gem/ruby/1.8.7/gems/rspec-1.2.9/lib/spec/runner/ command_line.rb:6:in `run'
 from /home/shot/.gem/ruby/1.8.7/gems/rspec-1.2.9/bin/spec:5
rake aborted!
Command /home/shot/.rvm/ruby-1.8.7-p174/bin/ruby -I"lib" "/home/ shot/.gem/ruby/1.8.7/gems/rspec-1.2.9/bin/spec" "spec/set_spec.rb" "spec/string_spec.rb" "spec/enumerable_spec.rb" "spec/file_spec.rb" "spec/art-decomp/graph_spec.rb" "spec/art-decomp/logging_spec.rb" "spec/art-decomp/arch_spec.rb" "spec/art-decomp/fsm_spec.rb" "spec/ art-decomp/sep_spec.rb" "spec/art-decomp/bipainter_spec.rb" "spec/ art-decomp/blanket_spec.rb" "spec/art-decomp/kiss_spec.rb" "spec/art- decomp/qv_generator/graph_colouring_spec.rb" "spec/art-decomp/ qv_generator/bipainting_spec.rb" "spec/art-decomp/qv_generator/ graph_merging_spec.rb" "spec/art-decomp/executable_spec.rb" "spec/ art-decomp/decomposer_spec.rb" "spec/art-decomp/qu_generator/ edge_labels_spec.rb" "spec/art-decomp/qu_generator/ block_table_spec.rb" "spec/art-decomp/uv_generator/ relevance_spec.rb" "spec/art-decomp/uv_generator/braindead_spec.rb" "spec/art-decomp/decomposition_spec.rb" "spec/art-decomp/b_spec.rb" "spec/integer_spec.rb" --options spec/spec.opts failed

(See full trace by running task with --trace)
s...@devielle:~/PhD/art-decomp$


I guess the problem is my way of monkey-patching the Set class;
I first ‘require 'set'’ to get the stdlib’s Set, and then
‘require_relative 'lib/set'’ to get my patches. But this approach
works in RSpec 1.2.8 and in all other applications of my code…

Any insight on whether I should fix my code or
is this a bug in RSpec would be most appreciated.

Hey Shot -

RSpec 1.2.9 adds ./lib and ./spec (from the project root) to the load path. So it sounds it's loading your custom 'set' before the one in stdlib.

I've run into load order problems like this before, and found that the safest bet is to have the extension at a different path than that of the core lib. So in this case, I'd recommend putting the 'set' extensions in ./lib/extensions/set (or something similar - anything other than ./lib/set), and then require 'set' _from that file_.

WDYT?

David


— Shot, who’s back to RSpec 1.2.8 for now
--
Content-type: lies/all-lies
Content-disposition: blatant
             [Nick Moffitt]
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to