Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:55:20+00:00 2026-06-10T08:55:20+00:00

I’m newbie on rails and testing rails applications. I try to test an existing

  • 0

I’m newbie on rails and testing rails applications. I try to test an existing rails application with rspec.
I’ve just finished model tests and i have to complete controller tests too.
But i have a problem with sign_in method on rspec. I’ve tried all solution methods on the internet but still i can’t sign in like a user with rspec.
here is the my controller code, it’s too simple;

class AboutController < ApplicationController
  def index
  end

  def how_it_works
  end

  def what_is
  end

  def creative_tips
  end

  def brand_tips
  end

  def we_are
  end

  def faq
  end
end

and here is the my spec code;

require 'spec_helper'

describe AboutController do

  before(:all) do
    @customer=Factory.create(:customer)
    sign_in @customer
  end

  context 'index page :' do

    it 'should be loaded successfully' do
      response.should be_success
    end

  end

end

Here is the my factory code;

Factory.define :unconfirmed_user, :class => User do |u|
  u.sequence(:user_name) {|n| "user_#{n}"}
  u.sequence(:email){|n| "user__#{n}@example.com"}
  u.sequence(:confirmation_token){|n| "confirm_#{n}"}
  u.sequence(:reset_password_token){|n| "password_#{n}"}
  u.password '123456'
  u.password_confirmation '123456'
  u.user_type :nil
end

Factory.define :user, :parent => :unconfirmed_user do |u|
  u.confirmed_at '1-1-2010'
  u.confirmation_sent_at '1-1-2010'
end

Factory.define :customer, :parent => :user do |u|
  u.user_type :customer
end

Finally here is the my spec_helper code

ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails)
require 'rspec/rails'
require "paperclip/matchers"

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|
  config.include Paperclip::Shoulda::Matchers
end

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end

RSpec.configure do |config|
  config.mock_with :rspec
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = true
end

gem file;

gem 'rails', '3.0.3'
gem 'mysql2', '< 0.3'
.
.
.
gem "devise" , "1.1.5"
.
.
.

group :test do
  gem 'shoulda'
  gem "rspec-rails", "~> 2.11.0"
  gem "factory_girl_rails"
end

and here is the error;

Failures:

  1) AboutController index page : should be loaded successfully
     Failure/Error: sign_in @customer
     NoMethodError:
       undefined method `env' for nil:NilClass
     # ./spec/controllers/about_controller_spec.rb:7:in `block (2 levels) in <top (required)>'

solution must be too easy but I’m newbie on rails and i can’t find it 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:55:21+00:00Added an answer on June 10, 2026 at 8:55 am

    You have to make the sign-in step inside the it block in order for rspec to be able to access the response, e.g.:

    it 'should be loaded successfully' do
      sign_in @customer
      response.should be_success
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.