Class: GreenPepper::DoWithExample

Inherits:
ExampleWithFixture show all
Defined in:
lib/greenpepper/example/dowithexample.rb

Constant Summary

Constants inherited from ExampleWithFixture

ExampleWithFixture::EXAMPLE_NAME_COLUMN, ExampleWithFixture::EXAMPLE_NAME_ROW, ExampleWithFixture::FIRST_DATA_ROW, ExampleWithFixture::FIXTURE_NAME_COLUMN, ExampleWithFixture::FIXTURE_NAME_ROW, ExampleWithFixture::HEADER_ROW

Instance Attribute Summary collapse

Attributes inherited from ExampleWithFixture

#fixture_arguments, #fixture_name, #headers

Instance Method Summary collapse

Methods inherited from ExampleWithFixture

#add_fixture_argument, #execute

Constructor Details

#initialize(fixture_name, line_factory = DoWithLineFactory.new) ⇒ DoWithExample

Returns a new instance of DoWithExample.



16
17
18
19
20
# File 'lib/greenpepper/example/dowithexample.rb', line 16

def initialize(fixture_name, line_factory = DoWithLineFactory.new)
  super fixture_name
  @lines = []
  @line_factory = line_factory
end

Instance Attribute Details

#linesObject (readonly)

Returns the value of attribute lines.



14
15
16
# File 'lib/greenpepper/example/dowithexample.rb', line 14

def lines
  @lines
end

Instance Method Details

#add_accept(function, result_column, *params) ⇒ Object



55
56
57
# File 'lib/greenpepper/example/dowithexample.rb', line 55

def add_accept(function, result_column, *params)
  @lines << @line_factory.create_accept(function, result_column, params)
end

#add_check(function, result_column, expected_val, *params) ⇒ Object



50
51
52
53
# File 'lib/greenpepper/example/dowithexample.rb', line 50

def add_check(function, result_column, expected_val, *params)
  @lines << @line_factory.create_check(function, 
    result_column, expected_val, params)
end

#add_function_call(function, result_column, *params) ⇒ Object



45
46
47
48
# File 'lib/greenpepper/example/dowithexample.rb', line 45

def add_function_call(function, result_column, *params)
  @lines << @line_factory.create_function_call(function,
    result_column, params)
end

#add_reject(function, result_column, *params) ⇒ Object



59
60
61
# File 'lib/greenpepper/example/dowithexample.rb', line 59

def add_reject(function, result_column, *params)
  @lines << @line_factory.create_reject(function, result_column, params)
end

#do_execute(results, fixture_class) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/greenpepper/example/dowithexample.rb', line 22

def do_execute(results, fixture_class)
  fixture = instantiate_fixture fixture_class

  if fixture.is_a? Class
    e = GreenPepperSecurityError.new(
      "Can't instantiate a subclass of Class.")
    results.add FIXTURE_NAME_ROW, FIXTURE_NAME_COLUMN, WriteExceptionExampleResult.new(e)
    return results
  end

  @lines.each_with_index{ |line, line_index|
    begin
      res = line.execute(fixture)
    rescue => error
      res = WriteExceptionExampleResult.new(error)
    end
    unless res.nil?
      results.add line_index + FIRST_DATA_ROW, line.result_column, res
    end
  }
  results
end