[英]Rspec controller test does not hit my controller action
I added an import
method to a controller, and it works just fine when I test it manually from my website, but it is failing in rspec. 我向控制器添加了一个
import
方法,当我从我的网站手动测试时,它工作得很好,但它在rspec中失败了。 Here is what my test looks like: 这是我的测试的样子:
require 'spec_helper'
describe PropertiesController do
let!(:user) { FactoryGirl.create(:user) }
before :each do
sign_in user
end
describe "should upload user properties" do
before do
post :import, spreadsheet: fixture_file_upload("/files/property_upload_template.xlsx")
end
it "should have created records" do
expect(Property.count).to eq 3
# Some other assertions
end
end
end
When I add puts
statements inside my import action, including on the very first line, none of them are apparently invoked. 当我在我的导入操作中添加
puts
语句时,包括在第一行,显然没有调用它们。 The test is generating no errors other than failing the assertions. 除了断言失败之外,测试不会产生任何错误。 Similarly, when I look at the test.log file, all that happens is the creation of my test user (and a devise confirmation email gets sent out), but it doesn't appear that the import action is ever hit.
类似地,当我查看test.log文件时,所有发生的事情都是我的测试用户的创建(并且发送了设备确认电子邮件),但似乎没有点击导入操作。 The test server seems to recognize the route fine, but it's not actually executing the action.
测试服务器似乎认识到路由正常,但它实际上并没有执行该操作。
Is there something wrong with my test configuration? 我的测试配置有问题吗?
I had been banging my head for a good couple hours, but I just figured it out. 我一直在敲我的头几个小时,但我只想出来了。 I needed to confirm the user in my user factory .
我需要在用户工厂中确认用户 。 I guess since I enabled the
confirmable
module in devise, and the user wasn't confirmed, it was silently not allowing me to authenticate... 我想因为我在设计中启用了可
confirmable
模块,并且用户未被确认,所以它默默地不允许我进行身份验证...
... Would sure be nice if rspec/rails/devise generated some sort of error pointing me to the problem here. ...如果rspec / rails / devise产生某种错误指向我这里的问题,肯定会很好。
For the sake of completeness, I'm adding in the code for confirming a user in the version of FactoryGirl at the time of that writing: 为了完整起见,我在编写本文时添加了用于在FactoryGirl版本中确认用户的代码:
FactoryGirl.define do
factory :confirmed_user, :parent => :user do
after(:create) { |user| user.confirm! }
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.