RSPEC-未定义的方法'允许'
我试图使ENV变量固执以访问 rails.env.production?,
context 'Rails environment is production' do
it 'returns the correct api production service' do
allow(ENV).to receive(:[]).with('RAILS_ENV').and_return('production')
expect(application.api_domain).to eql('https://api.some_url.com')
end
end
但是我总是会得到此错误
NoMethodError:
undefined method `allow' for #<RSpec::ExampleGroups::CesidApplication::CesidApplication::RailsEnvironmentIsDevelopment:0x00007fcc48cec518>
Did you mean? all
模块方法IM测试
module Cesid
module Application
def api_domain
uri = URI.parse(marketing_suite_url)
domain = PublicSuffix.parse(uri.host)
Rails.env.production? ? "https://api.#{domain.name}" : "https://api-#{domain.name}"
end
end
end
RSPEC版本
3.5.4
有什么想法吗?
I am trying to stub the env variable to access Rails.env.production?
context 'Rails environment is production' do
it 'returns the correct api production service' do
allow(ENV).to receive(:[]).with('RAILS_ENV').and_return('production')
expect(application.api_domain).to eql('https://api.some_url.com')
end
end
but I always get this error
NoMethodError:
undefined method `allow' for #<RSpec::ExampleGroups::CesidApplication::CesidApplication::RailsEnvironmentIsDevelopment:0x00007fcc48cec518>
Did you mean? all
Module method im testing
module Cesid
module Application
def api_domain
uri = URI.parse(marketing_suite_url)
domain = PublicSuffix.parse(uri.host)
Rails.env.production? ? "https://api.#{domain.name}" : "https://api-#{domain.name}"
end
end
end
Rspec version
3.5.4
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
配置
期望
语法在spec_helper.rb
like中,然后
允许
将工作Configure the
expect
syntax inspec_helper.rb
like:Then the
allow
will work