Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test to be future proof with similarity #6

Merged
merged 1 commit into from
Feb 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/a_minimal/output2.txt
Original file line number Diff line number Diff line change
@@ -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/.
Expand Down
2 changes: 1 addition & 1 deletion features/k_run_global.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

39 changes: 31 additions & 8 deletions features/step_definitions/clicumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -51,7 +56,7 @@
FileUtils.cp source, target
end

# When...run
## When...run

When(/^I run: (.+)$/) do |command|
@stdout, @stderr, @status = Open3.capture3 command
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -99,7 +122,7 @@
end
end

# Then...file
## Then...file

Then(/^the file "([^"]*)" should (not )?exist$/) do |file, negate|
if negate
Expand Down Expand Up @@ -133,7 +156,7 @@
end
end

# Then...dir
## Then...dir

Then(/^the (?:folder|dir|directory) "([^"]*)" should (not )?exist$/) do |dir, negate|
if negate
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'open3'
require 'similar_text'
1 change: 1 addition & 0 deletions runfile.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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