在升级到rails 4之后跟踪railscast以完成此过程,这样做,我已经破坏了我的用户测试套件。
user_spec.rb:
describe User do
before do
@user = User.new(email: "user@example.com",
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
这是rspec吐出的内容:
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)
这是我的宝石文件
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
可能导致自己遇到这些问题的原因是什么?谢谢!
更新: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
答案 0 :(得分:2)
subject
以块为参数。你需要说subject {@user}
。]
您收到的错误是因为Ruby试图将@user
视为Proc
对象。