Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Updates to refinement specs #158

Closed
wants to merge 1 commit into from

3 participants

@ajuckel

I've updated added a couple more specs based on my exploration of ruby 2.0.0.preview1.

@brixen
Owner

Would you be able to redo this on refinements branch?

@ajuckel

It appears that refinements have changed a bit since RubyConf, to be more syntactic rather than a simple runtime hack. I think that's good for the implementation (there were some sketchy behaviors in the specs that I had), but it means I'll have to experiment instead of simply copying over the specs.

@YorickPeterse

Closing this one due to the behaviour of refinements having changed quite a bit since, requiring quite a bit more of work for the specs to be up to shape. Also this branch can't be merged easily sadly. We can set up a new PR/issue when looking into refinements again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 3, 2012
  1. @ajuckel

    updates to refinement spec

    ajuckel authored
This page is out of date. Refresh to see the latest.
Showing with 49 additions and 7 deletions.
  1. +28 −7 core/kernel/using_spec.rb
  2. +21 −0 core/module/refinements_spec.rb
View
35 core/kernel/using_spec.rb
@@ -134,17 +134,38 @@ def bar; 'quux'; end
using StringRefinement
'hello'.foo
end.call.should == 'foo'
+ # Not sure we _want_ this behavior
+ 'foo'.foo.should == 'foo'
end
- ruby_bug "in a_matsuda's slides but does not appear to work", "2.0.1" do
- it "applies used refinements to nested closures inside module/class_eval" do
- mod = Module.new do
- using StringRefinement
- end
+ it "refinements in a lambda apply to the module in which the lambda was defined" do
+ mod = Module.new
+ l = mod.module_eval do
+ lambda do
+ using StringRefinement
+ end
+ end
+ mod2 = Module.new
+ mod2.module_eval do
+ l.call
+ end
+ lambda do
+ mod2.module_eval do
+ 'foo'.foo
+ end
+ end.should raise_error(NoMethodError)
+ mod.module_eval do
+ 'foo'.foo
+ end.should == 'foo'
+ end
- mod.module_eval { lambda { 'hello'.say } }.call.should == 'foo'
- mod.class_eval { lambda { 'hello'.say } }.call.should == 'foo'
+ it "applies used refinements to nested closures inside module/class_eval" do
+ mod = Module.new do
+ using StringRefinement
end
+
+ mod.module_eval { lambda { 'hello'.foo } }.call.should == 'foo'
+ mod.class_eval { lambda { 'hello'.foo } }.call.should == 'foo'
end
end
end
View
21 core/module/refinements_spec.rb
@@ -13,5 +13,26 @@
mod.refinements[String].should be_kind_of(Module)
mod.refinements[Enumerable].should be_kind_of(Module)
end
+ it "changes to the returned hash don't affect refinements" do
+ mod = Module.new do
+ refine(String){}
+ end
+ hash = mod.refinements
+ hash[Enumerable] = Module.new
+ mod.refinements.key?(Enumerable).should be_false
+ end
+ it "methods added to the anon methods do refine class" do
+ mod = Module.new do
+ refine(String) {}
+ end
+ mod.refinements[String].module_eval do
+ def manually_added
+ true
+ end
+ end
+ mod.module_eval do
+ "foo".manually_added
+ end.should be_true
+ end
end
end
Something went wrong with that request. Please try again.