【发布时间】:2014-02-04 21:08:24
【问题描述】:
我正在使用 rspec 编写单元测试。
我想模拟 Rails.env.develepment?返回真。我怎样才能做到这一点?。
我试过了
Rails.env.stub(:development?, nil).and_return(true)
它会抛出这个错误
activesupport-4.0.0/lib/active_support/string_inquirer.rb:22:in `method_missing': undefined method `any_instance' for "test":ActiveSupport::StringInquirer (NoMethodError)
更新 红宝石版本 ruby-2.0.0-p353, 轨道 4.0.0, rspec 2.11
describe "welcome_signup" do
let(:mail) { Notifier.welcome_signup user }
describe "in dev mode" do
Rails.env.stub(:development?, nil).and_return(true)
let(:mail) { Notifier.welcome_signup user }
it "send an email to" do
expect(mail.to).to eq([GlobalConstants::DEV_EMAIL_ADDRESS])
end
end
end
【问题讨论】:
标签: rspec rspec2 rspec-rails