Derptacos
Derptacos

Reputation: 177

Upgraded to Rails 4, rspec causing issues

Followed the railscasts on upgrading to rails 4 to complete the process, in doing so, I have broken my user test suite.

user_spec.rb :

describe User do

    before do
        @user = User.new(email: "[email protected]",
                   password: "foobar", password_confirmation: "foobar")
    end

    subject(@user)

    it { should respond_to(:email)}
    it { should respond_to(:password_digest)}
    it { should respond_to(:password)}
    it { should respond_to(:password_confirmation)}
    it { should respond_to(:authenticate)}
end

Here is what rspec is spitting out :

bundle exec rspec spec/models/user_spec.rb
/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.13.1/lib/rspec/core/memoized_helpers.rb:180:in
`define_method': tried to create Proc object without a block (ArgumentError)

Here is my gemfile

source 'https://rubygems.org'
ruby '2.0.0'

gem 'rails', '4.0.0'
gem 'bootstrap-sass', '2.3.2.0'
gem 'will_paginate'
gem 'bootstrap-will_paginate'
gem 'bcrypt-ruby', '3.0.1'

group :development, :test do
  gem 'sqlite3', '1.3.7'
  gem 'rspec-rails', '2.13.1'
end

# Gems used only for assets and not required
# in production environments by default.
gem 'sass-rails', '4.0.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.0'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails'
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

What could be causing myself to have these issues? Thank you!

UPDATE: user.rb:

class User < ActiveRecord::Base
  before_save {self.email = email.downcase}
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
        uniqueness: { case_sensitivity: false }

  has_secure_password
  validates :password, length: { minimum: 6 }   
end

Upvotes: 0

Views: 679

Answers (1)

Peter Alfvin
Peter Alfvin

Reputation: 29439

subject takes a block as an argument. You need to say subject {@user}.]

You're getting the error you're getting because Ruby is trying to treat @user as a Proc object.

Upvotes: 2

Related Questions