Mongoid self referencing with accepts_nested_attributes_for - ruby-on-rails

Model:
class Plan
include Mongoid::Document
# Fields
field :name, type: String
# Relationships
references_many :sub_plans,
:autosave => true,
:class_name => 'Plan',
:inverse_class_name => 'Plan',
:inverse_of => :super_plans
references_many :super_plans,
:class_name => 'Plan',
:inverse_class_name => 'Plan',
:inverse_of => :sub_plans
accepts_nested_attributes_for :sub_plans
# Validations
validates_presence_of :name
end
Test:
describe Plan do
it "should always have a name" do
plan = Plan.new
plan.save.should == false
plan[:name] = "World Domination"
plan.save.should == true
end
it "should allow nested plan creation" do
plan = Plan.new(:name => "World Domination", :sub_plans_attributes => {
:name => "Get $50b",
:sub_plans_attributes => {
:name => "Invent"
}
});
plan.sub_plans.count.should == 1
plan.sub_plans.first.name.should == "Get $50b"
plan.sub_plans.first.sub_plans.count.should == 1
plan.sub_plans.first.sub_plans.first.name.should == "Invent"
end
end
Output with -b:
Running spec/models/plan_spec.rb
.F
Failures:
1) Plan should allow nested plan creation
Failure/Error: plan = Plan.new(:name => "World Domination", :sub_plans_attributes => {
TypeError:
can't convert Symbol into String
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/relations/builders/nested_attributes/many.rb:67:in `delete'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/relations/builders/nested_attributes/many.rb:67:in `destroyable?'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/relations/builders/nested_attributes/many.rb:103:in `process'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/relations/builders/nested_attributes/many.rb:30:in `block in build'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/relations/builders/nested_attributes/many.rb:26:in `each'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/relations/builders/nested_attributes/many.rb:26:in `build'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/nested_attributes.rb:47:in `block (3 levels) in accepts_nested_attributes_for'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/attributes.rb:193:in `_assigning'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/nested_attributes.rb:45:in `block (2 levels) in accepts_nested_attributes_for'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/attributes/processing.rb:111:in `block in process_nested'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/attributes/processing.rb:110:in `each_pair'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/attributes/processing.rb:110:in `process_nested'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/attributes/processing.rb:122:in `process_pending'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/attributes/processing.rb:29:in `process'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/document.rb:131:in `block in initialize'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/relations/builders.rb:47:in `_building'
# /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.3.1/lib/mongoid/document.rb:127:in `initialize'
# ./spec/models/plan_spec.rb:11:in `new'
# ./spec/models/plan_spec.rb:11:in `block (2 levels) in <top (required)>'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `instance_eval'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `block in run'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:107:in `with_around_hooks'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:45:in `run'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:294:in `block in run_examples'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:290:in `map'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:290:in `run_examples'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:262:in `run'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `block (2 levels) in run'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `map'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `block in run'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/reporter.rb:12:in `report'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:21:in `run'
# /usr/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/monkey/spork/test_framework/rspec.rb:5:in `run_tests'
# /usr/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:13:in `block in run'
# /usr/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc9/lib/spork/forker.rb:21:in `block in initialize'
# /usr/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc9/lib/spork/forker.rb:18:in `fork'
# /usr/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc9/lib/spork/forker.rb:18:in `initialize'
# /usr/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:9:in `new'
# /usr/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:9:in `run'
# /usr/lib/ruby/gems/1.9.1/gems/spork-0.9.0.rc9/lib/spork/server.rb:48:in `run'
# /usr/lib/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
# /usr/lib/ruby/1.9.1/drb/drb.rb:1518:in `perform'
# /usr/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
# /usr/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
# /usr/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
Finished in 0.00917 seconds
2 examples, 1 failure
Failed examples:
rspec ./spec/models/plan_spec.rb:10 # Plan should allow nested plan creation
Why am I getting this error, and how can I get my many-many self reference working? I'm using Mongoid version 2.3.1 and Rails version 3.1.1. Thanks

After several hours spent trying several different combinations and finally giving up and sleeping on it, I have finally got it to work! Model:
class Plan
include Mongoid::Document
# Fields
field :name, type: String
# Relationships
has_and_belongs_to_many :subplans, :inverse_of => :parents, :class_name => 'Plan', :autosave => true
has_and_belongs_to_many :parents, :inverse_of => :subplans, :class_name => 'Plan', :autosave => true
accepts_nested_attributes_for :subplans
# Validations
validates_presence_of :name
end
Tests:
describe Plan do
it "should always have a name" do
plan = Plan.new
plan.save.should == false
plan[:name] = "World Domination"
plan.save.should == true
end
it "should have a nested relationship" do
root = Plan.create name: "Parent Plan"
child1 = root.subplans.create name: 'Child Plan #1'
child2 = Plan.create name: "Child Plan #2"
root.subplans << child2
root.subplans.size.should == 2
child1.parents.size.should == 1
child1.parents.first.should == root
child2.parents.size.should == 1
child2.parents.first.should == root
end
it "should accept nested attributes for subplans" do
plan = Plan.new :name => "root",
:subplans_attributes => [{:name => "child"}]
plan.save; plan.reload
plan.subplans.size.should == 1
plan.subplans.first.name.should == "child"
end
end

Related

Rspec 'trait not registered error when using Faker

I am trying to use Faker in FactoryBot in my Rails API tests.
The issue I am having that I keep getting this error:
KeyError:
Trait not registered: "first_name"
So far as I can tell I have configured everything right, based on Faker'd docs at least. So far as I can tell I have two actual traits, valid_user and invalid_user that I set like so...
let(:valid_attributes) { FactoryBot.attributes_for :api_v1_user, :valid_user }
let(:invalid_attributes) { FactoryBot.attributes_for :api_v1_user, :invalid_user }
Which are linked to the :api_v1_user factory.
What have I missed or done wrong?
Full Error:
8) /api/v1/users PATCH /update with invalid parameters renders a JSON response with errors for the api/v1_user
Failure/Error: let(:invalid_attributes) { FactoryBot.attributes_for(:api_v1_user, :invalid_user) }
KeyError:
Trait not registered: "first_name"
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/activesupport-6.0.2.2/lib/active_support/hash_with_indifferent_access.rb:191:in `fetch'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/activesupport-6.0.2.2/lib/active_support/hash_with_indifferent_access.rb:191:in `fetch'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/registry.rb:23:in `find'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/decorator.rb:10:in `method_missing'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/internal.rb:49:in `trait_by_name'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:114:in `trait_by_name'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:106:in `block in base_traits'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:106:in `map'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:106:in `base_traits'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:51:in `block in compile'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:50:in `compile'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:130:in `aggregate_from_traits_and_self'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:34:in `to_create'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/trait.rb:17:in `to_create'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:135:in `map'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:135:in `aggregate_from_traits_and_self'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition.rb:34:in `to_create'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/definition_hierarchy.rb:16:in `build_from_definition'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/factory.rb:125:in `build_hierarchy'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/factory.rb:88:in `compile'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/factory.rb:32:in `run'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/factory_runner.rb:29:in `block in run'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/activesupport-6.0.2.2/lib/active_support/notifications.rb:182:in `instrument'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/factory_runner.rb:28:in `run'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/factory_bot-5.1.2/lib/factory_bot/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
# ./spec/requests/api/v1/users_spec.rb:6:in `block (2 levels) in <top (required)>'
# ./spec/requests/api/v1/users_spec.rb:92:in `block (4 levels) in <top (required)>'
# ./spec/rails_helper.rb:19:in `block (3 levels) in <top (required)>'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/database_cleaner-1.8.4/lib/database_cleaner/generic/base.rb:16:in `cleaning'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/database_cleaner-1.8.4/lib/database_cleaner/configuration.rb:87:in `block (2 levels) in cleaning'
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/database_cleaner-1.8.4/lib/database_cleaner/configuration.rb:88:in `cleaning'
# ./spec/rails_helper.rb:18:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# KeyError:
# key not found: "first_name"
# /home/etherk1ll/.rvm/gems/ruby-2.7.0/gems/activesupport-6.0.2.2/lib/active_support/hash_with_indifferent_access.rb:191:in `fetch'
spec/factories/api/v1/users.rb
require 'faker'
FactoryBot.define do
factory :api_v1_user, class: 'Api::V1::User' do
trait :valid_user do
first_name { Faker::Name.first_name }
second_name { Faker::Name.second_name }
username { Faker::Internet.username }
email { Faker::Internet.safe_email }
password { Faker::Internet.password(min_length: 8) }
end
trait :invalid_user do
first_name nil
end
end
end
rails_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
RSpec.configure do |config|
config.use_transactional_fixtures = false
DatabaseCleaner.strategy = :truncation
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
config.before(:all) do
DatabaseCleaner.start
end
config.after(:all) do
DatabaseCleaner.clean
end
end
users_spec.rb
Truncated
RSpec.describe "/api/v1/users", type: :request do
let(:valid_attributes) { FactoryBot.attributes_for :api_v1_user, :valid_user }
let(:invalid_attributes) { FactoryBot.attributes_for :api_v1_user, :invalid_user }
let(:valid_headers) {
{}
}
describe "PATCH /update" do
context "with invalid parameters" do
it "renders a JSON response with errors for the api/v1_user" do
user = Api::V1::User.create! valid_attributes
patch api_v1_user_url(user),
params: { api_v1_user: invalid_attributes }, headers: valid_headers, as: :json
expect(response).to have_http_status(:unprocessable_entity)
expect(response.content_type).to eq("application/json")
end
end
end
end
Try wrapping the nil in brackets. FactoryBot eliminated support for static attributes in version 5, so if you're using a newer version, that'll be your problem. Brackets are now required.
trait :invalid_user do
first_name { nil }
end

Ruby on rails, Validation failed: Countries can't be blank

it "renders index page" do
projects_user = FactoryGirl.create(:projects_user)
get :index, id: projects_user.id
expect(response).to render_template :index
end
this is my controller test, when i run it it says: Validation failed: Countries can't be blank
I am new to stackoverflow and ruby soo any help i get is great
FilesController:
class FilesController < ApplicationController
before_filter :authenticate_user!
def index
#pu = ProjectsUser.find(params[:id])
debugger
#files = UserFile.includes(:user).where(project_id: #pu.id)
end
def new
#file = UserFile.new
end
def create
#file = UserFile.new(file_params)
if #file.save
flash[:success] = "File successfully uploaded!"
redirect_to files_path
else
#files = UserFile.includes(:user).where(user_id: current_user.id)
render :index
end
end
def destroy
#file = UserFile.find(params[:file_id])
if #file.destroy
flash[:success] = "File successfully deleted!"
redirect_to files_path
else
flash[:error] = "File could not be deleted."
redirect_to files_path
end
end
protected
def file_params
params.require(:user_file).permit(:file, :user_id, :created_at, :updated_at, :project_id)
end
end
Country controller:
class CountriesController < ApplicationController
def states
#states = State.where(country_id: params[:id]).all
return render :json => {success: true, status: 200, data: #states}
end
end
Country model:
class Country < ActiveRecord::Base
validates :name, presence: true
has_many :states
has_many :users
has_and_belongs_to_many :projects
validates :name, presence: true
end
Factory for country:
require 'ffaker'
FactoryGirl.define do
factory :country do
name {FFaker::AddressUS.country}
end
end
output of error:
ActiveRecord::RecordInvalid:
Validation failed: Countries can't be blank
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib /factory_girl/configuration.rb:18:in `block in initialize'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluation.rb:15:in `[]'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluation.rb:15:in `create'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:12:in `block in result'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:9:in `tap'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:9:in `result'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory.rb:42:in `run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:29:in `block in run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:28:in `run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:5:in `association'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluator.rb:33:in `association'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute/association.rb:19:in `block in to_proc'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluator.rb:77:in `instance_exec'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluator.rb:77:in `block in define_attribute'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:56:in `get'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:16:in `block (2 levels) in object'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `each'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `block in object'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `tap'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `object'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/evaluation.rb:12:in `object'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:9:in `result'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory.rb:42:in `run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:29:in `block in run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:28:in `run'
# /home/nemanja/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.8.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
# ./spec/controllers/files_controllers_spec.rb:31:in `block (3 levels) in <top (required)>'
UPDATE:
Factory for project, project has_and_belongs_to_many countries
require 'ffaker'
FactoryGirl.define do
factory :project do
sponsor_name "John Pare"
title "Anea"
start_date Date.new(2016, 5, 7)
end_date Date.new(2017, 3, 6)
description {FFaker::Lorem.paragraph}
number_of_sites_planned "5"
estimated_enrollment "24"
feasibility_questionnaire File.open("#{Rails.root}/spec/internal_spec_files/app.pdf")
association :disease_type
association :disease_condition
association :user
association :project_category
association :project_subcategory
after(:create) do |m|
m.countries << build(:country)
end
end
end
The problem is within the
projects_user = FactoryGirl.create(:projects_user)
the creation code (where you defined this factory) does not set a country and this is why you get an error.

Empty rspec fails when I add this custom validation to my User model

I have a user model, if I add this custom validation my empty rspec test fails:
validate :password_complexity
def password_complexity
if !password.blank?
errors.add(:password, "must contain a upper case character") if password.match(/[A-Z]/)
end
end
Rspec:
require 'rails_helper'
RSpec.describe User, type: :model do
end
I run rspec spec/models/user_spec.rb and I get:
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/validations.rb:79:in
raise_record_invalid': Validation failed: Password must contain a
upper case character, Password must contain a lower case character
(ActiveRecord::RecordInvalid) from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/validations.rb:43:in
save!' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/attribute_methods/dirty.rb:29:in
save!' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/transactions.rb:291:in
block in save!' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/transactions.rb:351:in
block in with_transaction_returning_status' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in
transaction' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in
transaction' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/transactions.rb:348:in
with_transaction_returning_status' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/transactions.rb:291:in
save!' from
/Users/blank/dev/gitserver/myapp/myappweb/app/models/user.rb:74:in
create_from_signup!' from
/Users/blank/dev/gitserver/myapp/myappweb/app/services/account_service.rb:16:in
block in create' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
block in transaction' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in
within_new_transaction' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
transaction' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in
transaction' from
/Users/blank/dev/gitserver/myapp/myappweb/app/services/account_service.rb:11:in
create' from
/Users/blank/dev/gitserver/myapp/myappweb/db/seeds.rb:172:in <top
(required)>' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in
load' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in
block in load' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in
load_dependency' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in
load' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/railties-4.2.5/lib/rails/engine.rb:547:in
load_seed' from
/Users/blank/dev/gitserver/myapp/myappweb/spec/spec_helper.rb:24:in
block (2 levels) in <top (required)>' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:424:in
instance_exec' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/example.rb:424:in
instance_exec' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/hooks.rb:357:in
run' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1724:in
block in run_hooks_with' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1724:in
each' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1724:in
run_hooks_with' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1679:in
with_suite_hooks' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:114:in
block in run_specs' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/reporter.rb:77:in
report' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:113:in
run_specs' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:89:in
run' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:73:in
run' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:41:in
invoke' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/gems/rspec-core-3.4.1/exe/rspec:4:in
<top (required)>' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/bin/rspec:22:inload' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/bin/rspec:22:in <main>' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/bin/ruby_executable_hooks:15:in
eval' from
/Users/blank/.rvm/gems/ruby-2.3.3#myapp/bin/ruby_executable_hooks:15:in
`'
Why is this happening? If I remove that custom validation, it runs fine.
My model is:
class User < ActiveRecord::Base
has_secure_password
belongs_to :account
validates :email, uniqueness: { scope: :account_id }
validates_presence_of :email
validates_presence_of :password, :password_confirmation, on: :create
validates_length_of :password, :minimum => 8, :maximum => 32, :allow_blank => false
#validate :password_complexity
def password_complexity
if !password.blank?
errors.add(:password, "must contain a upper case character") unless password.match(/[A-Z]/)
end
end
end
Change
errors.add(:password, "must contain a upper case character") if password.match(/[A-Z]/)
To
errors.add(:password, "must contain a upper case character") unless password.match(/[A-Z]/)

Rspec: Testing registarion routing in rails with devise

I'm Trying to build a simple Blog using rails 4 and For authentication I'm using Devise.
The blog is simple and it will only have one registered user which is the admin. so the registration page should be available when there are no users in the database else it will redirect to the home page.
I'm trying to learn testing in the process. So I started testing the RegistrationContrroler However it doesn't seem to pass.
class RegistrationsController < Devise::RegistrationsController
before_action :one_user_registered?, only: [:new, :create]
protected
def one_user_registered?
if ((User.count == 1) & (user_signed_in?))
redirect_to root_path
elsif User.count == 1
redirect_to new_user_session_path
end
end
end
Specs:
RSpec.describe RegistrationsController, type: :controller do
context "Admin already registred" do
it "cannot create new user" do
#user_attr = FactoryGirl.attributes_for(:user)
# Create Admin
User.create!(#user_attr)
#request.env["devise.mapping"] = Devise.mappings[:user]
post :create, user: #user_attr
User.count should eq_to(1)
end
end
end
spec/factories.rb :
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "user#{n}#example.com" }
password "secure"
end
factory :post do
sequence(:id){ |n| n }
sequence(:title) { |n| "Post title #{n}" }
body "Post body"
sequence(:slug) { |n| "Post title #{n}" }
end
end
routes.rb
Rails.application.routes.draw do
devise_for :users, controllers: { registrations: "registrations" }
authenticated :user do
resources :posts
end
unauthenticated :user do
resources :posts, only: [:show, :index]
end
root 'posts#index'
end
Stacktrace :
F
Failures:
1) RegistrationsController Admin already registred cannot create new user
Failure/Error: User.count should eq_to(1)
expected: 1
got: #<RegistrationsController:0x00000003a413b8 #_action_has_layout=true, #_routes=nil, #_headers={"Conten...enticatable]>, #req touest_format=:html, #marked_for_same_origin_verification=false, #current_user=nil>
(compared using ==)
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-support-3.5.0/lib/rspec/support.rb:87:in `block in <module:Support>'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-support-3.5.0/lib/rspec/support.rb:96:in `notify_failure'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/fail_with.rb:27:in `fail_with'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:38:in `handle_failure'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:27:in `with_matcher'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/memoized_helpers.rb:81:in `should'
# ./spec/controllers/registrations_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:252:in `instance_exec'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:252:in `block in run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:494:in `block in with_around_and_singleton_context_hooks'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:451:in `block in with_around_example_hooks'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:471:in `block in run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:611:in `block in run_around_example_hooks_for'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:336:in `call'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-rails-3.5.1/lib/rspec/rails/example/controller_example_group.rb:191:in `block (2 levels) in <module:ControllerExampleGroup>'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:441:in `instance_exec'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:441:in `instance_exec'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:382:in `execute_with'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:613:in `block (2 levels) in run_around_example_hooks_for'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:336:in `call'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-rails-3.5.1/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:441:in `instance_exec'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:441:in `instance_exec'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:382:in `execute_with'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:613:in `block (2 levels) in run_around_example_hooks_for'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:336:in `call'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:614:in `run_around_example_hooks_for'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/hooks.rb:471:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:451:in `with_around_example_hooks'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:494:in `with_around_and_singleton_context_hooks'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example.rb:249:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:627:in `block in run_examples'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:623:in `map'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:623:in `run_examples'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:589:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:590:in `block in run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:590:in `map'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:590:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:113:in `block (3 levels) in run_specs'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:113:in `map'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:113:in `block (2 levels) in run_specs'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/configuration.rb:1836:in `with_suite_hooks'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/reporter.rb:77:in `report'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:111:in `run_specs'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:87:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:71:in `run'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/lib/rspec/core/runner.rb:45:in `invoke'
# /home/chaker/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.5.1/exe/rspec:4:in `<top (required)>'
# /home/chaker/.rvm/gems/ruby-2.3.1/bin/rspec:23:in `load'
# /home/chaker/.rvm/gems/ruby-2.3.1/bin/rspec:23:in `<main>'
# /home/chaker/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
# /home/chaker/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
Finished in 0.08188 seconds (files took 1.95 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/controllers/registrations_controller_spec.rb:7 # RegistrationsController Admin already registred cannot create new user
You're missing a dot!
User.count.should eq_to(1)
Adding a should method is the way rspec patches all objects to support the should comparisons.
Preferable would be...
expect(User.count).to eq(1)
The error showed that the should by itself was received by the RegistrationsController, not by the User.count... and of course the RegistrationsController doesn't equal 1.

undefined method 'env' for nil:NilClass

This is what my spec file looks like: spec/api/v1/projects_spec.rb
require "spec_helper"
describe "/api/v1/projects", :type => :api do
context "projects viewable by this user" do
it "JSON" do
end
end
end
It contained a lot more but I deleted a lot of lines in an unsuccessful attempt to find the error which goes like this:
Failure/Error: Unable to find matching line from backtrace
NoMethodError: undefined method `env' for nil:NilClass
This piece of code is from the "Rails 3 in Action" by Ryan Bigg. The only other file it includes is: spec/support/api/helper.rb
module ApiHelper
include Rack::Test::Methods
def app
Rails.application
end
end
RSpec.configure do |c|
c.include ApiHelper, :type => :api
end
I've been trying to google the error for the past 1 hr and the closest thing that I found was this and as a result I deleted the code which used Devise::Test_Helpers. Sadly, its still not working.
Any help would be appreciated. Thank you so much.
Stack Trace
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/devise-2.0.4/lib/devise/test_helpers.rb:24:in `setup_controller_for_warden'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-rails-2.8.1/lib/rspec/rails/adapters.rb:15:in `block (2 levels) in setup'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:35:in `instance_eval'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:35:in `run_in'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:70:in `block in run_all'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:70:in `each'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:70:in `run_all'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:368:in `run_hook'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:292:in `block in run_before_each_hooks'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:292:in `each'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:292:in `run_before_each_hooks'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example.rb:217:in `run_before_each'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example.rb:79:in `block in run'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example.rb:173:in `with_around_hooks'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example.rb:77:in `run'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:355:in `block in run_examples'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:351:in `map'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:351:in `run_examples'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:337:in `run'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:338:in `block in run'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:338:in `map'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:338:in `run'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:28:in `map'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:28:in `block in run'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/reporter.rb:34:in `report'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:25:in `run'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
# /home/prakhar/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
You're still including Devise::TestHelpers somewhere. Check and see what "spec_helper" is loading.
Instead of just including the Devise Test Helper, you can specify it's type, so that it's not included in routing spec:
config.include Devise::TestHelpers, :type => :helper
config.include Devise::TestHelpers, :type => :controller

Resources