Class: TrueTest::Context
- Inherits:
-
Object
- Object
- TrueTest::Context
- Defined in:
- lib/true_test/context.rb
Instance Attribute Summary collapse
-
#setup ⇒ Object
Returns the value of attribute setup.
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
-
#evaluate(binding, &block) ⇒ Object
safe evaluation that creates a failed test if an exception is raised instead of blowing up entire suite.
- #fixtures ⇒ Object
- #setup_fixtures(binding, keys) ⇒ Object
- #teardown(binding) ⇒ Object
Instance Attribute Details
#setup ⇒ Object
Returns the value of attribute setup.
3 4 5 |
# File 'lib/true_test/context.rb', line 3 def setup @setup end |
Class Method Details
Instance Method Details
#description ⇒ Object
30 31 32 33 34 35 |
# File 'lib/true_test/context.rb', line 30 def description parts = [] parts += ['when', @setup] if @setup parts += ['with', fixtures.collect(&:description).join(' and ')] if fixtures.any? parts.join(' ') end |
#evaluate(binding, &block) ⇒ Object
safe evaluation that creates a failed test if an exception is raised instead of blowing up entire suite
37 38 39 40 41 42 43 |
# File 'lib/true_test/context.rb', line 37 def evaluate(binding, &block) begin binding.instance_eval &block rescue => e TrueTest::PositiveAssertion.new('not raise error', &block).evaluate binding end end |
#fixtures ⇒ Object
26 27 28 29 |
# File 'lib/true_test/context.rb', line 26 def fixtures @fixtures ||= [] @fixtures end |
#setup_fixtures(binding, keys) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/true_test/context.rb', line 11 def setup_fixtures(binding, keys) context = self keys.each do |key| self.evaluate binding do context.fixtures << TrueTest::Fixture.evaluate(key, binding) end end end |
#teardown(binding) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/true_test/context.rb', line 19 def teardown(binding) fixtures.each do |fixture| fixture.unbind binding end fixtures.clear @@context = nil end |