Uninitialized constant Production::POverview (NameError)
from /Users/simon_zhu/.rvm/gems/ruby-2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/syntax/default.rb:49:in `instance_eval'
from /Users/simon_zhu/.rvm/gems/ruby-2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/syntax/default.rb:49:in `run'
from /Users/simon_zhu/.rvm/gems/ruby-2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/syntax/default.rb:7:in `define'
from /Users/simon_zhu/Documents/original_version_carmel/carmel/spec/factories/poverview.rb:1:in `<top (required)>'
from /Users/simon_zhu/.rvm/gems/ruby-2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/find_definitions.rb:20:in `block (2 levels) in find_definitions'
from /Users/simon_zhu/.rvm/gems/ruby-2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/find_definitions.rb:19:in `each'
我有以下代码:
poverview.rb(工厂)
FactoryGirl.define do
factory :poverview, class: Production::POverview do
name "test"
status ["p", "d", "m"]
end
end
p_overview_controller_spec.rb(spec)
require 'spec_helper'
describe Production::POverviewController do
login_user
# GET Request to pod_info
describe 'GET pod_info' do
before(:each) do
@pods = Factory(:poverview)
get 'show', :format => :json, :name => @pods.name
get 'show', :format => :json, :status => @pods.status
end
it "should return the correct company when correct id is passed" do
body = JSON.parse(response.body)
for(pod in body[0])
if(pod['name'].eql? @pod.name)
@pod.status.should.include? pod['status']
end
end
end
end
这是我第一次为Factory Girl编写集成测试,我有这个未初始化的常量错误。
任何想法如何解决这个问题?
答案 0 :(得分:-1)
此外,您的测试设置看起来很奇怪。看起来你很容易混淆集成和控制器测试。
这是一篇可以帮助您入门的帖子。我建议做更多关于轨道测试的研究。 https://semaphoreapp.com/blog/2014/02/11/rails-testing-antipatterns-controllers.html