Spec RSpec model attribute setter

I'm using Sinatra (1.2) and RSpec (2.5) and would like to create a new object with an attribute TDD style. This is how the end result should look like:

class User
  def initialize(name)
    @name = name
  end
end

I know I have to write the example before the implementation but I'm trying to explain my question here. :) Here is the not working spec I have so far:

describe User
  it "creates a new user object" do
    name = mock("A name")
    user = mock(User) # shouldn't do this, see the reply's
    user.should_receive(:name=).with(name)
    User.new(name)
  end
end

When I run RSpec I get the "expected: 1 time, received 0 times" error. Any idea how I can explain RSpec I would like to assign the name attribute?

Note: I'm not using Rails, not using ActiveRecord or anything, just Ruby.

5
задан Cimm 9 April 2011 в 09:31
поделиться