RubyGems Navigation menu

at 0.1.3

# At `At` is a small library that allows you to access instance variables on an object as if they were `attr_accessor`s for testing purposes. Basically, `at` directly translates this: ```ruby value = object.instance_eval { @instance_variable } object.instance_eval { @instance_variable = "#{value}!" } ``` into this: ```ruby value = object.at.instance_variable object.at.instance_variable = "#{value}!" ``` ## Install ### Bundler: `gem 'at'` ### RubyGems: `gem install at` ## Usage If I want to test the output of the `full_name` method in my `User` class below, I would normally have three options for testing all possible outcomes; initialize a `User` object for each test case, initialize one `User` object and use `instance_eval` to set the instance variables individually, or create `attr_accessor`s for each instance variable I would like to test. In Rspec, I can use `assigns` to test the value of the instance variable, but I can't _get_ the value of the instance variable. `At` solves these problems. ```ruby require 'at' 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 describe User, '#full_name' do it 'should output the full name correctly' do subject.at.first_name = 'John' subject.at.last_name = 'Doe' subject.full_name.should == 'John Doe' end end ``` Check out the specs for a better usage example. ## Contributing * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it * Fork the project * Start a feature/bugfix branch * Commit and push until you are happy with your contribution * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. ## Copyright Copyright © 2012 Ryan Scott Lewis . The MIT License (MIT) - See LICENSE for further details.

Gemfile:
=

安装:
=

版本列表:

  1. 0.2.0 February 16, 2013 (9.0 KB)
  2. 0.1.4 December 11, 2012 (9.5 KB)
  3. 0.1.3 November 24, 2012 (11.0 KB)
  4. 0.1.2 October 07, 2011 (5.5 KB)
  5. 0.1.1 October 07, 2011 (5.0 KB)
显示所有版本 (共 6 个)

Runtime 依赖 (1):

version ~> 1.0.0

Development 依赖 (6):

fuubar ~> 1.1
github-markup ~> 0.7
guard-rspec ~> 2.1
guard-yard ~> 2.0
rb-fsevent ~> 0.9
redcarpet ~> 2.2.2

业主:

作者:

  • Ryan Scott Lewis

SHA 256 校验和:

=

下载总量 27,008

这个版本 4,024

版本发布:

许可:

需要的 Ruby 版本:

链接: