Dmytro Vasin
Dmytro Vasin

Reputation: 823

Rspec mistaken on start

i am new in Rspec, and i read the book 'rails 3 in action' and there i have Rspec testing:

spec/controlers/proect_controller_spec:

require 'spec_helper'

describe ProjectsController do
  let(:user) do
    user = Factory(:user)
    user.confirm!
    user
  end

  let(:project) { Factory(:project) }

  context "standard users" do

    it "cannot access the show action" do
      sign_in(:user, user)
    end

  end
end

spec/factories/user_factory.rb

Factory.define :user do |user|
  user.sequence(:email) { |n| "user#{n}@ticketee.com" }
  user.password "password"
  user.password_confirmation "password"
end

spec/support/factories.rb

Dir[Rails.root + "factories/*.rb"].each do |file|
  require file
end

spec/spec_helper

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require "email_spec"

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = true
  config.infer_base_class_for_anonymous_controllers = false
  config.order = "random"
end

gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.9'
gem 'pg'
gem 'devise'

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'dynamic_form'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :test, :development do
  gem 'rspec-rails', '~> 2.5'
end

group :test do
  gem 'capybara'
  gem 'database_cleaner'
  gem 'factory_girl'
  gem 'email_spec' # 122 page, for email confirmation
end

and when i start: rspec ./spec/controllers/projects_controller_spec.rb

i got:

 ProjectsController standard users cannot access the show action
     Failure/Error: user = Factory(:user)
     NoMethodError:
       undefined method `Factory' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x8e96710>

where i mistaken?...

Upvotes: 0

Views: 97

Answers (2)

nathanvda
nathanvda

Reputation: 50057

FactoryGirl's syntax has changed, now you can no longer write

Factory(:user)

but you should write

FactoryGirl.create(:user)

For more information see the getting started document. For more inforamtion about the upgrade to version 3.0 (including the deprecation of the old syntax), see this blogpost.

Upvotes: 1

David Chelimsky
David Chelimsky

Reputation: 9000

I think you want "factory_girl_rails", not "factory_girl": https://github.com/thoughtbot/factory_girl_rails

Upvotes: 2

Related Questions