我想检查包含有关更改控制器数据库的某些过程的操作是否成功。
"没有保存" ˚F
故障:
1)BuysController检查#new' s行为返回完成 失败/错误:期待(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&#39; s行为已完成
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
答案 0 :(得分:0)
您可能还想检查错误。
expect(buy.errors).to be_empty