【发布时间】:2014-08-12 19:59:44
【问题描述】:
我正在尝试创建一个mock object,我正在检查我的方法receives 是否正确param 和预期结果。
下面是我的spec。
require 'spec_helper'
describe User do
let(:username) {"test@test.com"}
let(:password) {"123"}
let(:code) {"0"}
context "when signing in" do
it "should sign in" do
user = double("user")
expected_results = {
"token": "123"
}
allow(user).to receive(:login).with({email: username, password: password, code: code})
.and_return(expected_results)
expect(user.login).to eq(expected_results)
end
end
end
有没有办法将我的 json 与 it 块分开并保留在外面?
【问题讨论】:
-
@zetetic:我看了,但没有帮助...
-
我不清楚这个问题。您只想在示例之外设置
expected_results的值吗?您可以通过在内部上下文中添加let来做到这一点。 -
@zetetic:你能举出那个例子吗,因为它失败了。我也在做正确的测试方式吗?
标签: ruby-on-rails ruby json ruby-on-rails-3 rspec