Rails 3 , RSpec 2.0.0.beta.11

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)
@cloning_vector.sequence.should_receive(:new).with(“content” =>
“New Content”).and_return(@sequence)

What am I doing wrong?.. Thanks for your help

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

 @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?