Using stubs – is the classic TDD approach where unit tests are designed to check state. A general core workflow would be calling a method of an object/type with subsequent verification that the state has been updated.
Using mocks – is a TDD variation – BDD – that aims to track behaviour. Typical scenario would be creating a pre-programmed workflow and check if a real-world object follows the predefined behaviour.
In rspec_helper.rb we need to add
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
and in spec_controller.rb file
before (:each) do
@user = FactoryGirl.create(:user)
if using FactroyGirl.
we can also add
in each and every controller where controller is protected. followed by sign_in @user
I hope it help.
when i generated the post model, a spec/factories/posts.rb was created,.
I removed that and everything works.