运行以下测试套件时:
require 'spec_helper'
describe User do
before { @user = User.(name: "Example User", email: "user@example.com" }
subject { @user }
it { should respond_to(:name) }
it { should respond_to(:email) }
end
我收到此错误:
Failure/Error: before { @user = User.(name: "Example User", email: "user@example.com") }
NoMethodError:
undefined method `call' for #<Class:0x007fdfd5dd8008>
# ./spec/models/user_spec.rb:15:in `block (2 levels) in <top (required)>'
创建用户在控制台中工作正常,它会响应方法。
答案 0 :(得分:5)
您遇到语法错误:
before { @user = User.(name: "Example User", email: "user@example.com" }
.
与左括号之间不应有User
。你也错过了右括号。尝试:
before { @user = User.new(name: "Example User", email: "user@example.com") }
如果您想知道特定的错误消息,在较新的Ruby版本中.()
就像call
一样:
l = lambda { |x| x * x }
#=> #<Proc:0x007fe5d3907188@(pry):39 (lambda)>
l.call(3)
#=> 9
l.(3)
#=> 9