Class: Pione::TestHelper::TestPioneMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/pione/test-helper/lang-helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, option = {}) ⇒ TestPioneMethod

Returns a new instance of TestPioneMethod.



153
154
155
156
157
158
# File 'lib/pione/test-helper/lang-helper.rb', line 153

def initialize(path, option={})
  dir = File.dirname(path)
  name = File.basename(path, ".rb").sub("spec_", "")
  @path = File.join(dir, 'data', '%s.yml' % name)
  @transformer_option = make_transformer_option(option)
end

Instance Method Details

#make_test_items(testcases) ⇒ Object



184
185
186
187
188
189
190
191
192
193
# File 'lib/pione/test-helper/lang-helper.rb', line 184

def make_test_items(testcases)
  if testcases
    testcases.map do |testcase|
      head = testcase.keys.first
      TestPioneMethodItem.new(head.to_s, testcase[head].to_s, @transformer_option)
    end
  else
    []
  end
end

#make_transformer_option(option) ⇒ Object



177
178
179
180
181
182
# File 'lib/pione/test-helper/lang-helper.rb', line 177

def make_transformer_option(option)
  transformer_option = {}
  transformer_option[:package_name] = option[:package_name] || "Test"
  transformer_option[:filename] = option[:filename] || "Test.pione"
  transformer_option
end

#runObject

Test pione method.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/pione/test-helper/lang-helper.rb', line 161

def run
  YAML.load_file(@path).each do |title, testcases|
    items = make_test_items(testcases)

    describe "pione method test cases" do
      describe title do
        items.each do |item|
          it '%s should be %s' % [item.expr_string, item.expectation_string] do
            item.test
          end
        end
      end
    end
  end
end