From 4dd1fc56a960638e58b557a9600ccfb11b1d72ea Mon Sep 17 00:00:00 2001 From: DannyB Date: Fri, 19 Feb 2016 08:57:19 +0000 Subject: [PATCH] update test to be future proof with similarity --- examples/a_minimal/output2.txt | 2 +- features/k_run_global.feature | 2 +- features/step_definitions/clicumber.rb | 39 ++++++++++++++++++++------ features/support/env.rb | 1 + runfile.gemspec | 1 + 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/examples/a_minimal/output2.txt b/examples/a_minimal/output2.txt index a7b4059..d6af1fc 100644 --- a/examples/a_minimal/output2.txt +++ b/examples/a_minimal/output2.txt @@ -1,4 +1,4 @@ -Runfile engine v0.6.0 +Runfile engine v0.x.x Tip: Type 'run make' or 'run make name' to create a runfile. For global access, place named.runfiles in ~/runfile/ or in /etc/runfile/. diff --git a/features/k_run_global.feature b/features/k_run_global.feature index f15f511..b26e74e 100644 --- a/features/k_run_global.feature +++ b/features/k_run_global.feature @@ -6,5 +6,5 @@ Feature: Run Global (Bang) Scenario: Show proper usage Given I am in the "examples/a_minimal" folder When I run "run!" - Then the output should be like "output2.txt" + Then the output should resemble "output2.txt" diff --git a/features/step_definitions/clicumber.rb b/features/step_definitions/clicumber.rb index 5357ea0..45d6a5c 100644 --- a/features/step_definitions/clicumber.rb +++ b/features/step_definitions/clicumber.rb @@ -10,10 +10,10 @@ $original_dir = nil end -# Given...dir +## Given...dir Given(/^I am in the "([^"]+)" (?:folder|dir|directory)$/) do |dir| - $original_dir = Dir.pwd + $original_dir = Dir.pwd unless $original_dir Dir.chdir dir end @@ -33,7 +33,12 @@ end end -# Given...file +Given(/^the (?:folder|dir|directory) "([^"]*)" is like "([^"]*)"$/) do |target, source| + FileUtils.cp_r source, target +end + + +## Given...file Given(/^the file "([^"]*)" (does not )?exists?$/) do |file, negate| if negate @@ -51,7 +56,7 @@ FileUtils.cp source, target end -# When...run +## When...run When(/^I run: (.+)$/) do |command| @stdout, @stderr, @status = Open3.capture3 command @@ -61,7 +66,14 @@ @stdout, @stderr, @status = Open3.capture3 command end -# Then...output +## When...dir + +When(/^I go into the "([^"]*)" (?:folder|dir|directory)$/) do |dir| + $original_dir = Dir.pwd unless $original_dir + Dir.chdir dir +end + +## Then...output Then(/^the (error )?output should (not )?be like "([^"]*)"$/) do |stderr, negate, file| stream = stderr ? @stderr : @stdout @@ -72,6 +84,17 @@ end end +Then(/^the (error )?output should (not )?resemble "([^"]*)"(?: by "(\d{1,2})%?")?$/) do |stderr, negate, file, percentage| + stream = stderr ? @stderr : @stdout + similarity = stream.similar File.read(file) + percentage ||= 90 + if negate + expect(similarity).to_not be >= percentage.to_f + else + expect(similarity).to be >= percentage.to_f + end +end + Then(/^the (error )?output should (not )?match "([^"]*)"$/) do |stderr, negate, content| stream = stderr ? @stderr : @stdout if negate @@ -99,7 +122,7 @@ end end -# Then...file +## Then...file Then(/^the file "([^"]*)" should (not )?exist$/) do |file, negate| if negate @@ -133,7 +156,7 @@ end end -# Then...dir +## Then...dir Then(/^the (?:folder|dir|directory) "([^"]*)" should (not )?exist$/) do |dir, negate| if negate @@ -151,7 +174,7 @@ end end -# Then...exit code +## Then...exit code Then(/^the (?:status|exit) code should (not )?be "([^"]*)"$/) do |negate, code| if negate diff --git a/features/support/env.rb b/features/support/env.rb index 4aa2138..3658cc4 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1 +1,2 @@ require 'open3' +require 'similar_text' diff --git a/runfile.gemspec b/runfile.gemspec index dd49c2d..4cdda61 100644 --- a/runfile.gemspec +++ b/runfile.gemspec @@ -23,4 +23,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'cucumber', '~> 2.3' s.add_development_dependency 'rspec-expectations', '~> 3.4' s.add_development_dependency 'rdoc', '~> 4.2' + s.add_development_dependency 'similar_text', '~> 0.0.4' end