Class: Given

Inherits:
Object show all
Includes:
Sapphire::Testing::Executable
Defined in:
lib/sapphire/DSL/Scenarios/given.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sapphire::Testing::Executable

#Report, #execute, #pend

Constructor Details

#initialize(parent, pre, text, &block) ⇒ Given

Returns a new instance of Given.



13
14
15
16
17
18
19
20
21
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 13

def initialize(parent, pre, text, &block)
  @value = text
  @text = pre + text.to_s
  @block = block
  @when = []
  @and = []
  @parent = parent
  @results = []
end

Instance Attribute Details

#andObject (readonly)

Returns the value of attribute and.



9
10
11
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 9

def and
  @and
end

#blockObject (readonly)

Returns the value of attribute block.



6
7
8
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 6

def block
  @block
end

#finallyObject (readonly)

Returns the value of attribute finally.



7
8
9
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 7

def finally
  @finally
end

#parentObject (readonly)

Returns the value of attribute parent.



10
11
12
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 10

def parent
  @parent
end

#resultsObject (readonly)

Returns the value of attribute results.



11
12
13
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 11

def results
  @results
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 5

def text
  @text
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 4

def value
  @value
end

#whenObject (readonly)

Returns the value of attribute when.



8
9
10
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 8

def when
  @when
end

Instance Method Details

#add_and(pre, text, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 42

def add_and(pre, text, &block)
  if(self.value.is_a? Pending or text.is_a? Pending)
    self.and << And.new(self, Pending.new(pre + text.to_s), &block)
  elsif(self.value.is_a? Broken)
    self.and << And.new(self, Broken.new(pre + text.to_s), &block)
  else
    self.and << And.new(self, pre + text.to_s, &block)
  end
end

#add_finally(finally) ⇒ Object



38
39
40
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 38

def add_finally(finally)
  @finally = finally
end

#add_when(pre, text, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 23

def add_when(pre, text, &block)
  if(self.value.is_a? Pending)
    @when << When.new(self, pre, Pending.new(text.to_s), &block)
  elsif(self.value.is_a? Broken)
    @when << When.new(self, pre, Broken.new(text), &block)
  else
    x = When.new(self, pre, text, &block)
    @when << x
  end
end

#AddResult(result) ⇒ Object



52
53
54
55
56
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 52

def AddResult(result)
  result.item = self
  @results << result
  self.parent.result.AddChild(result)
end

#last_whenObject



34
35
36
# File 'lib/sapphire/DSL/Scenarios/given.rb', line 34

def last_when()
  @when.last
end