Reputation: 1335
I'm just wondering if I understend test in a proper way.
The model tests should be done without mocking, eg.:
rspec
model.name = 'test'
model.save
model.should eq('test')
and the controllers should be based on mocking:
rspec
model.should_receive(:save).and_return(true)
controller
def action
...
if model.save
...
end
Summing up: controllers are tested without any true data. All data are "provide" by stubs and mocks in contrast to model layer which operates on ... db?
but I assume that model also should be mocked
model.name = 'test'
model.should_receive(:save)
model.should eq('test')
but I dont see sense of testing like this because I don't test the save method.
Upvotes: 0
Views: 648
Reputation: 6034
As a general rule of thumb that is how I go about it.
Using your example, if you have tested that the save
method in your model spec, you don't need to test it again in the controller, all you need to know is that it's called.
Essentially you need to test the behaviour of the controller, not how the model reacts to it.
Upvotes: 1