[rspec-users] Rails 3 , RSpec 2.0.0.beta.11

Matt Wynne matt at mattwynne.net
Sat Jun 12 03:13:47 EDT 2010


On 11 Jun 2010, at 23:54, juange wrote:

> Hi,
> 
> I was doing some testing to mi controller and a error raise, and it's
> driving me crazy. This are the lines that I wanna test:
> 
>    @cloning_vector = CloningVector.new(params[:cloning_vector])
>    @cloning_vector.sequence = Sequence.new(params[:sequence])
> 
> What I'm trying to do is following:
> 
>      @cloning_vector = mock_model(CloningVector)
>      @sequence = mock_model(Sequence)
> 
>      CloningVector.should_receive(:new).with("name" => "New
> cloning_vector", "cloning_vector_type" =>
> 1).and_return(@cloning_vector)

This line is the one with the mistake on it:

>      @cloning_vector.sequence.should_receive(:new).with("content" =>
> "New Content").and_return(@sequence)

Which class received the :new message in the code you're testing? Not @cloning_vector.sequence, but Sequence. Just the same way as you've stubbed CloningVector.new, you need to stub Sequence.new.

Make sense?

> 
> What am I doing wrong?..... Thanks for your help
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list