I’m working with Sinatra and RSpec. I have this in lib/auth.rb
class Person
attr_accessor :password if ENV['RACK_ENV'] == 'test'
....
I want to execute this code when I’m testing with Rspec, but it doesn’t work. This is my spec file:
describe Person
it 'should match the password' do
@james = Person.new(foo, 'bar')
@james.password.should == 'bar'
end
end
I don’t want @james.password to be accessible outside of this model, but to be able to access it from the Rspec file or in the testing environment. Is there any code to make attr_accessor work only in the testing environment?
Are you actually setting
ENV['RACK_ENV']when running your tests?Try adding
to the start of your test file.