Sha256: a3a71d51cd25fd0ce226df48c5de90842e459b8be684c4dccbee65892a206ad4

Contents?: true

Size: 1.46 KB

Versions: 20

Compression:

Stored size: 1.46 KB

Contents

require 'date'
require 'active_support'
require 'chronic'

module CucumberValueParser
  def coerce_value(value)
    # what is this, PHP?
    if value.blank?
      nil
    elsif value == 'true'
      true
    elsif value == 'false'
      false
    elsif value =~ /\d+.*,.*\d/
      value
    elsif value =~ /\d+\.\d+/
      value.to_f
    elsif value =~ /^0/
      value
    elsif value =~ /^\d+$/
      value.to_i
    elsif value =~ /Address:/
      value.sub(/Address:\s*/,'')
    elsif value.is_a?(String) and date = Chronic.parse(value)
      date
    else
      value
    end
  end

  def compare_values(a, b)
    if b.blank?
      a.should be_blank
    elsif a.is_a? Time
      b = Chronic.parse b unless b.is_a?(Time)
      a.should == b
    elsif a.is_a? Date 
      b = Date.parse b unless b.is_a?(Date)
      a.should == b
    elsif b =~ /\d+.*,.*\d/
      a.should == b
    elsif b =~ /\d+\.\d+/
      b = b.to_f
      a.to_f.should be_close(b, 0.00001)
    elsif b =~ /^0/
      a.to_s.should == b
    elsif b =~ /^\d+$/
      b = b.to_i
      a.to_i.should == b
    else
      a.should == b
    end
  end

  def equality?(a, b)
    if b.blank?
      a.blank?
    elsif a.is_a? Date or a.is_a? Time
      b = Date.parse b
      a == b
    elsif b =~ /\d+.*,.*\d/
      a == b
    elsif b =~ /\d+\.\d+/
      (a.to_f - b.to_f).abs <= 0.00001
    elsif b =~ /^0/
      a == b
    elsif b =~ /^\d+$/
      a.to_i == b.to_i
    else
      a == b
    end
  end
end

include CucumberValueParser

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
sniff-0.6.7 lib/test_support/cucumber/support/values.rb
sniff-0.6.6 lib/test_support/cucumber/support/values.rb
sniff-0.6.5 lib/test_support/cucumber/support/values.rb
sniff-0.6.4 lib/test_support/cucumber/support/values.rb
sniff-0.6.3 lib/test_support/cucumber/support/values.rb
sniff-0.6.2 lib/test_support/cucumber/support/values.rb
sniff-0.6.1 lib/test_support/cucumber/support/values.rb
sniff-0.6.0 lib/test_support/cucumber/support/values.rb
sniff-0.5.3 lib/test_support/cucumber/support/values.rb
sniff-0.5.2 lib/test_support/cucumber/support/values.rb
sniff-0.5.1 lib/test_support/cucumber/support/values.rb
sniff-0.5.0 lib/test_support/cucumber/support/values.rb
sniff-0.4.12 lib/test_support/cucumber/support/values.rb
sniff-0.4.11 lib/test_support/cucumber/support/values.rb
sniff-0.4.10 lib/test_support/cucumber/support/values.rb
sniff-0.4.9 lib/test_support/cucumber/support/values.rb
sniff-0.4.7 lib/test_support/cucumber/support/values.rb
sniff-0.4.6 lib/test_support/cucumber/support/values.rb
sniff-0.4.5 lib/test_support/cucumber/support/values.rb
sniff-0.4.4 lib/test_support/cucumber/support/values.rb