Class: TrueTest::Fixture
- Inherits:
-
Object
- Object
- TrueTest::Fixture
- Defined in:
- lib/true_test/fixture.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#key ⇒ Object
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
- #evaluate(binding) ⇒ Object
-
#initialize(key, &block) ⇒ Fixture
constructor
A new instance of Fixture.
- #unbind(binding) ⇒ Object
Constructor Details
#initialize(key, &block) ⇒ Fixture
Returns a new instance of Fixture.
19 20 21 22 |
# File 'lib/true_test/fixture.rb', line 19 def initialize(key, &block) @key = key @block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
3 4 5 |
# File 'lib/true_test/fixture.rb', line 3 def block @block end |
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/true_test/fixture.rb', line 3 def key @key end |
Class Method Details
.evaluate(key, binding) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/true_test/fixture.rb', line 8 def evaluate(key, binding) fixture = registry[key] raise "No fixture found in registry with key #{key}: #{registry.keys.inspect}" unless fixture fixture.evaluate binding fixture end |
.register(key, &block) ⇒ Object
5 6 7 |
# File 'lib/true_test/fixture.rb', line 5 def register(key, &block) registry[key] = TrueTest::Fixture.new(key, &block) end |
.registry ⇒ Object
14 15 16 17 |
# File 'lib/true_test/fixture.rb', line 14 def registry @@registry ||= {} @@registry end |
Instance Method Details
#description ⇒ Object
23 24 25 |
# File 'lib/true_test/fixture.rb', line 23 def description @key.to_s.gsub('_', ' ') end |
#evaluate(binding) ⇒ Object
26 27 28 29 |
# File 'lib/true_test/fixture.rb', line 26 def evaluate(binding) @result = binding.instance_eval &@block binding.instance_variable_set "@#{@key}", @result end |
#unbind(binding) ⇒ Object
30 31 32 |
# File 'lib/true_test/fixture.rb', line 30 def unbind(binding) binding.instance_variable_set "@#{@key}", nil end |