【发布时间】:2018-01-21 08:38:27
【问题描述】:
我想做什么
我想检查一个包含一些关于更改控制器数据库的过程的操作是否成功。
错误
“不保存” F
失败:
1) BuysController 检查#new 的行为返回完成 失败/错误:expect(buy.trading_status).to eq("done")
expected: "done"
got: "pending"
(compared using ==)
# ./spec/controllers/buys_controller_spec.rb:27:in `block (3 levels) in <top (required)>'
在 0.14739 秒内完成(文件加载需要 3.68 秒) 1 个示例,1 个失败
失败的例子:
rspec ./spec/controllers/buys_controller_spec.rb:6 # BuysController 检查 #new 的行为返回完成
代码
require 'rails_helper'
include BuysHelper
RSpec.describe BuysController, type: :controller do
describe "check #new's behavior" do
it "return done" do
User.create(name:"hhhvv",email:"gggjggg@gmail.com")
p User.find(1)
Currency.create(name:"hello",user_id:1)
Sell.create(
id:1,
user_id: 1,
currency_id:1,
amount:100,
price:100,
trading_status:"pending")
buy = Buy.new(
id:1,
user_id: 1,
currency_id:1,
amount:100,
price:100,
trading_status:"pending"
)
if buy.save
market_checker
else
p "no save"
end
expect(buy.trading_status).to eq("done")
end
end
end
我尝试过的
rake db:test:prepare
rake db:migrate RAILS_ENV=test
【问题讨论】:
-
使用
save!查看引发的错误。不建议在应用程序中使用,但在调试此类事情的测试中确实很有帮助。 -
谢谢,由于验证,我刚刚收到错误消息。
标签: rspec rspec-rails