Class: TrueTest::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/true_test/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#setupObject

Returns the value of attribute setup.



3
4
5
# File 'lib/true_test/context.rb', line 3

def setup
  @setup
end

Class Method Details

.currentObject



5
6
7
8
# File 'lib/true_test/context.rb', line 5

def current
  @@context ||= TrueTest::Context.new
  @@context
end

Instance Method Details

#descriptionObject



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

#fixturesObject



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