【发布时间】:2012-02-04 03:21:20
【问题描述】:
我正在与 Sinatra 和 RSpec 合作。我在 lib/auth.rb 中有这个
class Person
attr_accessor :password if ENV['RACK_ENV'] == 'test'
....
我想在使用 Rspec 进行测试时执行此代码,但它不起作用。这是我的规范文件:
describe Person
it 'should match the password' do
@james = Person.new(foo, 'bar')
@james.password.should == 'bar'
end
end
我不希望 @james.password 在此模型之外访问,但能够从 Rspec 文件或在测试环境中访问它。是否有任何代码可以使attr_accessor 仅在测试环境中工作?
【问题讨论】:
标签: testing rspec sinatra environment