text: Use `at` to easily get/set instance variables on an object.
  - Gem:
  - Source:
  - Documentation:
  At is a small library provides an
  at method for all Objects which allows you to access instance variables
  on an object as if they were accessors for testing purposes, usually within test setups and teardowns.
  Basically,
  at directly translates this:
  value = user.instance_eval { <a href="/name">@name</a> } user.instance_eval { <a href="/name">@name</a> = "#{value}!" }
  into this:
  value = user.at.name user.at.name = "#{value}!"
  Use Case
  lib/user.rb
  class User def initialize(first_name=nil, last_name=nil) @first_name, @last_name = first_name, last_name end def full_name [@first_name, @last_name].compact.join(" ") end end
  spec/spec_helper.rb
  require 'user' require 'at/setup'
  spec/user_spec.rb
  describe User do describe '#full_name' do before :all do subject.at.first_name = 'John' subject.at.last_name = 'Doe' end it 'should output the full name correctly' do subject.full_name.should == 'John Doe' end end end
  I wouldn't recommend this for testing purposes. If you have to set instance variables as part of your setup, you're doing it wrong.
  What about: ?
  @deradon I would much rather write
  object.at.foo_bar = 'value'rather than
  object.instance_variable_set(:@foo_bar, 'value'), wouldn't you?
  Oh snap. This is probably more sensible than the pry-syntax_hacks way.
  @soccer022483 How would you test a method such as
  def errors; @errors ||= []; end?
  I much prefer this:
  @ryanscottlewis I would test the public behavior of the method, without making implementation assumptions.
  See:
  Consider this: changing the name of your instance variable would break your tests, but you haven't changed functionality.
  @ryanscottlewis I wouldn't. It's less surprising and doesn't add a dependency to my project.
  Haven't we learned anything from the failed matching DSL in RSpec? You write "object.at.name = foo", but it would be better as "at(object).name = foo". It's poor form to inject methods into Object, even for testing.
  Add a comment