Ruby on rails NoMethodError:未定义的方法'call';

Ruby on rails NoMethodError:未定义的方法'call';,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,运行以下测试套件时: 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: be

运行以下测试套件时:

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)>'
失败/错误:在{@user=user之前。(名称:“示例用户”,电子邮件:”user@example.com") }
命名错误:
未定义的方法“调用”#
#./spec/models/user_spec.rb:15:in'block(2层)in'

在控制台中创建用户工作正常,它会响应这些方法。

您有一个语法错误:

before { @user = User.(name: "Example User", email: "user@example.com" }
用户
和左括号之间不应存在
。此外,您还缺少右括号。尝试:

before { @user = User.new(name: "Example User", email: "user@example.com") }
如果您想知道具体的错误消息,在较新的Ruby版本中,
的工作原理类似于
调用

l = lambda { |x| x * x }
#=> #<Proc:0x007fe5d3907188@(pry):39 (lambda)>
l.call(3)
#=> 9
l.(3)
#=> 9
l=lambda{| x | x*x}
#=> #
l、 电话(3)
#=> 9
l、 (三)
#=> 9