0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.