[rspec-users] (no subject)

aslak hellesoy aslak.hellesoy at gmail.com
Tue Aug 14 17:17:19 EDT 2007


On 8/14/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
>
> How would you spec out something like the following:
>

You're starting with the code, trying to tape on the spec afterwards.
This is always a difficult task and is exactly what BDD and RSpec is
trying to get you away from.

Have you tried writing the RSpec examples first? I'd help you with an
example if I knew what you're trying to achieve from a functional (not
code) standpoint.

Aslak

> 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
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list