Class: ManaMana::TDSL::TestCaseNode

Inherits:
Node
  • Object
show all
Defined in:
lib/manamana/tdsl/nodes.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #name

Instance Method Summary collapse

Constructor Details

#initialize(name = '', children = {}) ⇒ TestCaseNode

Returns a new instance of TestCaseNode.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/manamana/tdsl/nodes.rb', line 50

def initialize(name='', children={})
  unless children.class == Hash
    raise "Second parameter must be a Hash"
  end

  children[:variables]     = children.delete(:variables) || VariablesNode.new
  children[:preconditions] = children.delete(:preconditions) || PreconditionsNode.new
  children[:cleanup]       = children.delete(:cleanup) || CleanupNode.new
  children[:script]        = children.delete(:script) || ScriptNode.new

  @regex = Regexp.new("^#{name}$", Regexp::IGNORECASE)

  super name, children
end

Instance Attribute Details

#regexObject (readonly)

Returns the value of attribute regex.



48
49
50
# File 'lib/manamana/tdsl/nodes.rb', line 48

def regex
  @regex
end

Instance Method Details

#==(other_node) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/manamana/tdsl/nodes.rb', line 65

def ==(other_node)
  self.class       == other_node.class &&
  name             == other_node.name &&
  variables        == other_node.variables &&
  preconditions    == other_node.preconditions &&
  cleanup          == other_node.cleanup &&
  script           == other_node.script
end

#cleanupObject



138
139
140
# File 'lib/manamana/tdsl/nodes.rb', line 138

def cleanup
  children[:cleanup].children
end

#preconditionsObject



134
135
136
# File 'lib/manamana/tdsl/nodes.rb', line 134

def preconditions
  children[:preconditions].children
end

#scriptObject



142
143
144
# File 'lib/manamana/tdsl/nodes.rb', line 142

def script
  children[:script].children
end

#test(string) ⇒ Object



74
75
76
# File 'lib/manamana/tdsl/nodes.rb', line 74

def test(string)
  !(regex =~ string).nil?
end

#translate(requirement) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/manamana/tdsl/nodes.rb', line 78

def translate(requirement)
  spec = ""
  spec << "  describe '#{ requirement }' do\n"
  spec << "    before do\n"

  # Make the $1, $2, etc variables available to this spec
  spec << "      #{ regex.inspect } =~ \"#{ requirement }\"\n"

  preconditions.each do |step|
    str = step.name.dup
    variables.each do |assignment|
      assignment.gsub! str
    end

    spec << "      Steps.call \"" + str + "\"\n"
  end

  spec << "    end\n\n"

  spec << "    after do\n"

  cleanup.each do |step|
    str = step.name.dup
    variables.each do |assignment|
      assignment.gsub! str
    end

    spec << "      Steps.call \"" + str + "\"\n"
  end

  spec << "    end\n\n"

  spec << "    it 'must pass' do\n"

  script.each do |step|
    str = step.name.dup
    variables.each do |assignment|
      assignment.gsub! str
    end

    spec << "      Steps.call \"" + str + "\"\n"
  end

  if script.length == 0
    spec << "      raise 'Undefined test case'\n"
  end

  spec << "    end\n"
  spec << "  end\n"
  spec
end

#variablesObject



130
131
132
# File 'lib/manamana/tdsl/nodes.rb', line 130

def variables
  children[:variables].children
end