Sha256: 5f90d5e0f65cc85474bc8b3c09e8cc34ecfecd4e57e30955b6d81a4c97196a4f

Contents?: true

Size: 1.62 KB

Versions: 37

Compression:

Stored size: 1.62 KB

Contents

require 'singleton'

class DiffTool
  include Singleton

  def diff source, target
    phrases1 = []

    keywords_exp1 = /^(Given|When|Then|And|But)/

    File.open(source).each_line do |line|
      line = line.strip

      if line !~ /^#/ and line =~ keywords_exp1
        word = line.scan(keywords_exp1)[0][0]

        phrases1 << line[word.size..-1].strip
      end
    end

    phrases2 = []

    keywords_exp2 = /step\s+('|")(.*)('|")/

    File.open(target).each_line do |line|
      line = line.strip

      if line !~ /^#/ and line =~ keywords_exp2
        phrases2 << line.scan(keywords_exp2)[0][1]
      end
    end

    ok = true

    phrases1.each_with_index do |phrase, index|
      phrase1 = phrase.clone.gsub("\"", "'")
      phrase2 = phrases2[index]

      if phrase1.nil? or phrase2.nil?
        puts "Different amount of steps:"
        puts "  source: #{phrases1.size}"
        puts "  target: #{phrases2.size}"
        ok = false
        break
      end

      params = phrase2.gsub(/:\w+\S/).to_a

      params.each do |param|
        new_param = param.gsub(":", "")

        phrase1.gsub!(%r{<#{new_param}>}, param)
      end

      params.each do |param|
        phrase1.gsub!(/'(\w|\s)*'/, param)
      end

      params.each do |param|
        phrase1.gsub!(/'(.)*'/, param)
      end

      if phrase1 != phrase2
        puts "Fail:"
        puts "  #{phrase}"
        puts "  #{phrases2[index]}"
        ok = false
      else
        puts "OK:"
        puts "  #{phrase}"
        puts "  #{phrases2[index]}"
      end
    end

    if ok
      puts "Everything is OK."
    else
      puts "Some errors exist!"
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
acceptance_test-1.11.7 lib/acceptance_test/diff_tool.rb
acceptance_test-1.11.6 lib/acceptance_test/diff_tool.rb
acceptance_test-1.11.5 lib/acceptance_test/diff_tool.rb
acceptance_test-1.11.4 lib/acceptance_test/diff_tool.rb
acceptance_test-1.11.3 lib/acceptance_test/diff_tool.rb
acceptance_test-1.11.2 lib/acceptance_test/diff_tool.rb
acceptance_test-1.11.1 lib/acceptance_test/diff_tool.rb
acceptance_test-1.11.0 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.12 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.11 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.10 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.9 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.8 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.7 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.6 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.5 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.4 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.3 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.2 lib/acceptance_test/diff_tool.rb
acceptance_test-1.10.1 lib/acceptance_test/diff_tool.rb