The Difference between Mocks and Stubs

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.


Rspec test case for protected controller with devise “before_filter :authenticate_user!”

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)
sign_in @user

if using FactroyGirl.


we can also add

include Devise::TestHelpers

in each and every controller where controller is protected. followed by sign_in @user

I hope it help.