How would you spec out something like the following:
def a_method
x = Class.new do
include Enumerable
end
# do something here with x
end
describe "The Anonymous Class" do
before :each do
@anonymous_class = mock Class
Class.stub!(:new).and_return @anonymous_class
end
it "should create a new anonymous class" do
Class.should_receive(:new)
a_method
end
it "should include Enumerable" do
#... what goes here?
end
end
One thought I've had on this is that we should be able to do
something like this:
it "should include Enumerable" do
Class.should_receive(:new).with(&lambda {
include Enumerable
}).and_return true
end
The serious problem with implementing this is that in Ruby 1.8.6 proc
equality occurs at the syntax/parser tree level, so this spec would
fail:
describe "Two procs" do
it "should be equal with the same bodies" do
@proc1 = lambda { do_something }
@proc2 = lambda { do_something }
@proc1.should == @proc2
end
end
Any good thoughts on how to get around this?
Scott