0

I'm currently new to RSpec and trying to implement some Controller testing with RSpec

In my Rails app, I'm using Devise as my authentication system. My question is, When we test a controller which uses some authentication system (in my case Devise), what is the standard practice?

Is it

1 - to skip the authentication

or

2 - to authenticate the controller

as per the question, following is my controller

require File.dirname(__FILE__) + '/../spec_helper'

describe ProjectsController do
  include Devise::TestHelpers

  p "starting..."

  before(:each) do
    p "in before method"
    @request.env["devise.mapping"] = Devise.mappings[:user]
    sign_in Factory.create(:user)
  end

  it "should create a project" do
   p "should create a project"
  end

  after(:each) do
    @user.destroy unless @user.nil?
  end
end 

I can only see 'starting', But why its not going to "in before method" and "should create a project"

I'm using Rspec2 and Rails2 on Ubuntu.

halfer
  • 19,824
  • 17
  • 99
  • 186
sameera207
  • 16,547
  • 19
  • 87
  • 152

1 Answers1

0

Check this: Stubbing Devise in rSpec and Rails3.

Standard practice is not skipping authentication, but effectively making sure that a correct user is logged in (for devise).

Referring to your code: have you tried to create some real test? E.g. something as simple as

it "gets index" do
  get :index
  response.status.should be == 200
end

I am not sure why you are not seeing the print-statements. Either rspec skips the empty step (there is no real code), or because something else went wrong. But honestly, I am not even sure if using p inside rspec works.

A tool like rubymine allows you to easily debug your specs if you want to step into it (which imho is a better approach then the scattered p statements).

Community
  • 1
  • 1
nathanvda
  • 49,707
  • 13
  • 117
  • 139