Rhett Sutphin
2010-Nov-03 22:39 UTC
[rspec-users] Apparent regression in rspec 2 on ruby 1.9: constant resolution fails in describes in nested modules
Hi, I''ve converted a couple of my smaller libraries'' spec suites to rspec 2 with no trouble. (I''m enjoying the new version -- thanks to all involved.) I''m trying to convert one a larger suite now and I''ve run into two problems on ruby 1.9.1 (but not 1.8.7) related to constant resolution in describes inside of modules. One of the problems haven''t been able to reproduce in a simple test case, but the other one I have. Here''s the reproducible one: # ---- baz_spec.rb module Foo module Quux class Baz def name "noise" end end end end module Foo::Quux describe Baz do it "has a name" do Baz.new.name.should == ''noise'' end end end # ---- This spec passes on rspec 2.0.1 and 1.3.0 on Ruby 1.8.7: ---- $ ruby -v ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0] $ spec _1.3.0_ baz_spec.rb . Finished in 0.002011 seconds 1 example, 0 failures $ rspec _2.0.1_ baz_spec.rb . Finished in 0.00077 seconds 1 example, 0 failures ---- It also passes on rspec 1.3.0 on Ruby 1.9.1. On rspec 2.0.1, it fails: ---- $ ruby -v ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.3.0] $ spec _1.3.0_ baz_spec.rb . Finished in 0.020187 seconds 1 example, 0 failures $ rspec _2.0.1_ baz_spec.rb F Failures: 1) Foo::Quux::Baz has a name Failure/Error: Baz.new.name.should == ''noise'' uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Baz # ./baz_spec.rb:14:in `block (2 levels) in <module:Quux>'' Finished in 0.00159 seconds 1 example, 1 failure ---- Is this a bug or expected behavior in rspec 2? I''ll file an issue if it''s a bug -- this would be against rspec-core, correct? Thanks, Rhett
David Chelimsky
2010-Nov-05 12:13 UTC
[rspec-users] Apparent regression in rspec 2 on ruby 1.9: constant resolution fails in describes in nested modules
On Nov 3, 2010, at 5:39 PM, Rhett Sutphin wrote:> Hi, > > I''ve converted a couple of my smaller libraries'' spec suites to rspec 2 with no trouble. (I''m enjoying the new version -- thanks to all involved.) I''m trying to convert one a larger suite now and I''ve run into two problems on ruby 1.9.1 (but not 1.8.7) related to constant resolution in describes inside of modules. One of the problems haven''t been able to reproduce in a simple test case, but the other one I have. Here''s the reproducible one: > > # ---- baz_spec.rb > > module Foo > module Quux > class Baz > def name > "noise" > end > end > end > end > > module Foo::Quux > describe Baz do > it "has a name" do > Baz.new.name.should == ''noise'' > end > end > end > > # ---- > > This spec passes on rspec 2.0.1 and 1.3.0 on Ruby 1.8.7: > > ---- > $ ruby -v > ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0] > $ spec _1.3.0_ baz_spec.rb > . > > Finished in 0.002011 seconds > > 1 example, 0 failures > $ rspec _2.0.1_ baz_spec.rb > . > > Finished in 0.00077 seconds > 1 example, 0 failures > ---- > > It also passes on rspec 1.3.0 on Ruby 1.9.1. On rspec 2.0.1, it fails: > > ---- > $ ruby -v > ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.3.0] > $ spec _1.3.0_ baz_spec.rb > . > > Finished in 0.020187 seconds > > 1 example, 0 failures > $ rspec _2.0.1_ baz_spec.rb > F > > Failures: > 1) Foo::Quux::Baz has a name > Failure/Error: Baz.new.name.should == ''noise'' > uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Baz > # ./baz_spec.rb:14:in `block (2 levels) in <module:Quux>'' > > Finished in 0.00159 seconds > 1 example, 1 failure > ---- > > Is this a bug or expected behavior in rspec 2? I''ll file an issue if it''s a bug -- this would be against rspec-core, correct?Same issue just came up on this list yesterday: http://groups.google.com/group/rspec/browse_thread/thread/60cfab923dbf007a
Rhett Sutphin
2010-Nov-05 14:19 UTC
[rspec-users] Apparent regression in rspec 2 on ruby 1.9: constant resolution fails in describes in nested modules
Hi, On Nov 5, 2010, at 7:13 AM, David Chelimsky wrote:> On Nov 3, 2010, at 5:39 PM, Rhett Sutphin wrote: > >> Hi, >> >> I''ve converted a couple of my smaller libraries'' spec suites to rspec 2 with no trouble. (I''m enjoying the new version -- thanks to all involved.) I''m trying to convert one a larger suite now and I''ve run into two problems on ruby 1.9.1 (but not 1.8.7) related to constant resolution in describes inside of modules. One of the problems haven''t been able to reproduce in a simple test case, but the other one I have. Here''s the reproducible one: >>[details snipped]>> >> Is this a bug or expected behavior in rspec 2? I''ll file an issue if it''s a bug -- this would be against rspec-core, correct? > > Same issue just came up on this list yesterday: http://groups.google.com/group/rspec/browse_thread/thread/60cfab923dbf007aYeah, those were both me -- I sent the first one from the wrong address. Sorry about the noise. To summarize what I''ve learned for someone who comes across this later: 1.9.1 has some bugs regarding scoping. While rspec 1.3.x worked around these bugs in some fashion, rspec 2 will not. (Since 1.9.1 is a superseded revision of the experimental version of ruby, this seems reasonable to me.) I filed an issue[1] requesting that the non-support of 1.9.1 be noted in the upgrade guide. Myron Marston helpfully pointed out a workaround for the minimal example I posted -- my actual specs are more complex, but I''m sure there are similar workarounds. For the particular gem I''m working on (an internal one) dropping support for 1.9.1 in favor of 1.9.2 is a fine option, so I''m doing that instead. [1]: https://github.com/rspec/rspec-core/issues/209 Thanks for the help, Rhett> _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users