haiti 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ Haiti
2
+ =====
3
+
4
+ Aruba provides Cucumber helpers for command line programs, but it's way more sophisticated than I can understand,
5
+ so I wind up reinventing that wheel in miniature for a lot of projects. This is just an extraction of that.
6
+ It aims to be simple and easy to understand/extend.
7
+
8
+ It's barely featured, currently the only features are what I extracted from SeeingIsBelieving's test suite. I'll
9
+ add more to it as I need them, or you're welcome to. Its testing is entirely in cucumber at the moment, and there
10
+ are no negative tests to assert that things don't work, so if anyone winds up working on it, I wouldn't mind that.
11
+
12
+
13
+ To run tests
14
+ ============
15
+
16
+ cd tests
17
+ bundle
18
+ bundle exec cucumber
19
+
20
+ Todo
21
+ ====
22
+
23
+ * Add tests showing that curlies get interpreted where expected
24
+ * Add tests proving that bin gets stuck in the path
25
+ * Add tests for negative assertions (currently if all step defs were empty, this would pass the suite)
26
+
27
+ Things that would be nice, but probably won't ever happen, b/c honestly, how often am I really going to touch this lib?
28
+ =======================================================================================================================
29
+
30
+ * all step defs work with single or double quotes
31
+ * multiple bin directories
32
+ * don't fucking pollute the World (currently this is how I get `eval_curlies` in there)
33
+ * assertions about the existence and contents of files
34
+ * a "given I'm in a clean directory" which wipes out the proving grounds
35
+
36
+ License
37
+ =======
38
+
39
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
40
+ Version 2, December 2004
41
+
42
+ Copyright (C) 2013 Josh Cheek <josh.cheek@gmail.com>
43
+
44
+ Everyone is permitted to copy and distribute verbatim or modified
45
+ copies of this license document, and changing it is allowed as long
46
+ as the name is changed.
47
+
48
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
49
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
50
+
51
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "haiti/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "haiti"
7
+ s.version = Haiti::VERSION
8
+ s.authors = ["Josh Cheek"]
9
+ s.email = ["josh.cheek@gmail.com"]
10
+ s.homepage = "https://github.com/JoshCheek/haiti"
11
+ s.summary = %q{Simple Cucumber steps for command line programs}
12
+ s.description = "Aruba provides Cucumber helpers for command line programs, but it's way more sophisticated than I can understand, " \
13
+ "so I wind up reinventing that wheel in miniature for a lot of projects. This is just an extraction of that. " \
14
+ "It aims to be simple and easy to understand/extend."
15
+ s.license = "WTFPL"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "cucumber", "~> 1.0"
23
+ s.add_dependency "rspec", "~> 2.0" # I don't actually know where the cutoff is, but I'm not doing anything fancy here
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'haiti/config'
2
+ require 'haiti/command_line_helpers'
3
+ require 'haiti/step_definitions'
4
+
5
+ # move this somewhere better
6
+ Before { Haiti::CommandLineHelpers.make_proving_grounds }
7
+
8
+ module GeneralHelpers
9
+ def eval_curlies(string)
10
+ string.gsub(/{{(.*?)}}/) { eval $1 }
11
+ end
12
+ end
13
+
14
+ World GeneralHelpers
@@ -0,0 +1,64 @@
1
+ require 'fileutils'
2
+ require 'open3'
3
+
4
+ module Haiti
5
+ module CommandLineHelpers
6
+ Invocation = Struct.new :stdout, :stderr, :status do
7
+ def exitstatus
8
+ status.exitstatus
9
+ end
10
+ end
11
+
12
+ extend self
13
+
14
+ def write_file(filename, body)
15
+ in_proving_grounds do
16
+ FileUtils.mkdir_p File.dirname filename
17
+ File.open(filename, 'w') { |file| file.write body }
18
+ end
19
+ end
20
+
21
+ def execute(command, stdin_data=nil)
22
+ stdin_data ||= ''
23
+ in_proving_grounds do
24
+ with_bin_in_path do
25
+ Invocation.new *Open3.capture3(command, stdin_data: stdin_data)
26
+ end
27
+ end
28
+ end
29
+
30
+ def in_proving_grounds(&block)
31
+ Dir.chdir proving_grounds_dir, &block
32
+ end
33
+
34
+ def proving_grounds_dir
35
+ config.proving_grounds_dir
36
+ end
37
+
38
+ def make_proving_grounds
39
+ FileUtils.mkdir_p proving_grounds_dir
40
+ end
41
+
42
+ def bin_dir
43
+ config.bin_dir
44
+ end
45
+
46
+ def path_to(filename)
47
+ in_proving_grounds { File.join proving_grounds_dir, filename }
48
+ end
49
+
50
+ # workaround for Ruby 2.0 bug where passing the new path as the first arg wasn't working
51
+ # bug report submitted here: http://bugs.ruby-lang.org/issues/8004
52
+ def with_bin_in_path
53
+ original_path = ENV['PATH']
54
+ ENV['PATH'] = "#{bin_dir}:#{ENV['PATH']}"
55
+ yield
56
+ ensure
57
+ ENV['PATH'] = original_path
58
+ end
59
+
60
+ def config
61
+ Haiti.config
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ module Haiti
2
+ Config = Struct.new :bin_dir, :proving_grounds_dir
3
+
4
+ def self.config
5
+ @config ||= Config.new
6
+ end
7
+
8
+ def self.configure(&block)
9
+ block.call config
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ Given('the file "$filename" "$body"') { |filename, body| Haiti::CommandLineHelpers.write_file filename, eval_curlies(body) }
2
+ Given('the file "$filename":') { |filename, body| Haiti::CommandLineHelpers.write_file filename, eval_curlies(body) }
3
+ Given('I have the stdin content "$content"') { |content| @stdin_data = eval_curlies(content) }
4
+ Given('I have the stdin content:') { |content| @stdin_data = eval_curlies(content) }
5
+ When('I run "$command"') { |command| @last_executed = Haiti::CommandLineHelpers.execute command, @stdin_data }
6
+ When("I run '$command'") { |command| @last_executed = Haiti::CommandLineHelpers.execute command, @stdin_data }
7
+ Then(/^(stderr|stdout) is:$/) { |stream_name, output| @last_executed.send(stream_name).chomp.should == eval_curlies(output) }
8
+ Then(/^(stderr|stdout) is ["'](.*?)["']$/) { |stream_name, output| @last_executed.send(stream_name).chomp.should == eval_curlies(output) }
9
+ Then(/^(stderr|stdout) is empty$/) { |stream_name| @last_executed.send(stream_name).should == '' }
10
+ Then(/^(stderr|stdout) is not empty$/) { |stream_name| @last_executed.send(stream_name).chomp.should_not be_empty }
11
+ Then(/^(stderr|stdout) includes "([^"]*)"$/) { |stream_name, content| @last_executed.send(stream_name).should include eval_curlies(content) }
12
+ Then('the exit status is $status') { |status| @last_executed.exitstatus.to_s.should == status }
@@ -0,0 +1,3 @@
1
+ module Haiti
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'haiti', path: '..'
4
+ gem 'cucumber'
5
+ gem 'rspec'
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ haiti (1.0.0)
5
+ cucumber (~> 1.0)
6
+ rspec (~> 2.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ builder (3.2.0)
12
+ cucumber (1.2.1)
13
+ builder (>= 2.1.2)
14
+ diff-lcs (>= 1.1.3)
15
+ gherkin (~> 2.11.0)
16
+ json (>= 1.4.6)
17
+ diff-lcs (1.2.4)
18
+ gherkin (2.11.6)
19
+ json (>= 1.7.6)
20
+ json (1.7.7)
21
+ rspec (2.13.0)
22
+ rspec-core (~> 2.13.0)
23
+ rspec-expectations (~> 2.13.0)
24
+ rspec-mocks (~> 2.13.0)
25
+ rspec-core (2.13.1)
26
+ rspec-expectations (2.13.0)
27
+ diff-lcs (>= 1.1.3, < 2.0)
28
+ rspec-mocks (2.13.1)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ cucumber
35
+ haiti!
36
+ rspec
@@ -0,0 +1,18 @@
1
+ Feature:
2
+ Scenario:
3
+ Given I have the stdin content "content"
4
+ When I run "cat"
5
+ Then stdout is "content"
6
+
7
+ Scenario:
8
+ Given I have the stdin content:
9
+ """
10
+ some
11
+ content
12
+ """
13
+ When I run "cat"
14
+ Then stdout is:
15
+ """
16
+ some
17
+ content
18
+ """
@@ -0,0 +1,13 @@
1
+ Feature:
2
+ Scenario:
3
+ Given the file "file1" "body{{0+1}}"
4
+ When I run 'cat file1'
5
+ Then stdout is "body1"
6
+
7
+ Scenario:
8
+ Given the file "file2":
9
+ """
10
+ body{{1+1}}
11
+ """
12
+ When I run 'cat file2'
13
+ Then stdout is "body2"
@@ -0,0 +1,6 @@
1
+ require 'haiti'
2
+
3
+ Haiti.configure do |config|
4
+ config.proving_grounds_dir = File.expand_path '../../../proving_grounds', __FILE__
5
+ config.bin_dir = File.expand_path '../../../bin', __FILE__
6
+ end
@@ -0,0 +1,8 @@
1
+ Feature:
2
+ Scenario:
3
+ When I run "true"
4
+ Then the exit status is 0
5
+
6
+ Scenario:
7
+ When I run "false"
8
+ Then the exit status is 1
@@ -0,0 +1,63 @@
1
+ Feature:
2
+
3
+ # stdout is ...
4
+ Scenario: stdout single quotes
5
+ When I run "ruby -e 'puts %(hi)'"
6
+ Then stdout is 'hi'
7
+
8
+ Scenario: stdout double quotes
9
+ When I run "ruby -e 'puts %(hi)'"
10
+ Then stdout is "hi"
11
+
12
+ Scenario: stdout multiline
13
+ When I run "ruby -e 'puts %(hi), %(bye)'"
14
+ Then stdout is:
15
+ """
16
+ hi
17
+ bye
18
+ """
19
+
20
+ # stderr is ...
21
+ Scenario: stderr single quotes
22
+ When I run "ruby -e '$stderr.puts %(hi)'"
23
+ Then stderr is 'hi'
24
+
25
+ Scenario: stderr double quotes
26
+ When I run "ruby -e '$stderr.puts %(hi)'"
27
+ Then stderr is "hi"
28
+
29
+ Scenario: stderr multiline
30
+ When I run "ruby -e '$stderr.puts %(hi), %(bye)'"
31
+ Then stderr is:
32
+ """
33
+ hi
34
+ bye
35
+ """
36
+
37
+ # stdout is / is not empty
38
+ Scenario: stdout is empty
39
+ When I run "ruby -e ''"
40
+ Then stdout is empty
41
+
42
+ Scenario: stdout is not empty
43
+ When I run "ruby -e '$stdout.puts %(a)'"
44
+ Then stdout is not empty
45
+
46
+ # stderr is / is not empty
47
+ Scenario: stderr is empty
48
+ When I run "ruby -e ''"
49
+ Then stdout is empty
50
+
51
+ Scenario: stderr is not empty
52
+ When I run "ruby -e '$stderr.puts %(a)'"
53
+ Then stderr is not empty
54
+
55
+ # stdout includes
56
+ Scenario: stdout includes
57
+ When I run "ruby -e '$stdout.puts %(abc)'"
58
+ Then stdout includes "b"
59
+
60
+ # stderr includes
61
+ Scenario: stderr includes
62
+ When I run "ruby -e '$stderr.puts %(abc)'"
63
+ Then stderr includes "b"
@@ -0,0 +1,8 @@
1
+ Feature:
2
+ Scenario:
3
+ When I run "echo hi"
4
+ Then stdout is "hi"
5
+
6
+ Scenario:
7
+ When I run 'echo bye'
8
+ Then stdout is "bye"
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haiti
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Josh Cheek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ none: false
21
+ name: cucumber
22
+ type: :runtime
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '1.0'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '2.0'
36
+ none: false
37
+ name: rspec
38
+ type: :runtime
39
+ prerelease: false
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: '2.0'
45
+ none: false
46
+ description: Aruba provides Cucumber helpers for command line programs, but it's way
47
+ more sophisticated than I can understand, so I wind up reinventing that wheel in
48
+ miniature for a lot of projects. This is just an extraction of that. It aims to
49
+ be simple and easy to understand/extend.
50
+ email:
51
+ - josh.cheek@gmail.com
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - Readme.md
57
+ - haiti.gemspec
58
+ - lib/haiti.rb
59
+ - lib/haiti/command_line_helpers.rb
60
+ - lib/haiti/config.rb
61
+ - lib/haiti/step_definitions.rb
62
+ - lib/haiti/version.rb
63
+ - test/Gemfile
64
+ - test/Gemfile.lock
65
+ - test/features/given_i_have_stdin_content.feature
66
+ - test/features/given_the_file.feature
67
+ - test/features/support/env.rb
68
+ - test/features/then_exit_status_is.feature
69
+ - test/features/then_stream_is.feature
70
+ - test/features/when_i_run.feature
71
+ homepage: https://github.com/JoshCheek/haiti
72
+ licenses:
73
+ - WTFPL
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ none: false
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ none: false
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.23
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Simple Cucumber steps for command line programs
96
+ test_files:
97
+ - test/Gemfile
98
+ - test/Gemfile.lock
99
+ - test/features/given_i_have_stdin_content.feature
100
+ - test/features/given_the_file.feature
101
+ - test/features/support/env.rb
102
+ - test/features/then_exit_status_is.feature
103
+ - test/features/then_stream_is.feature
104
+ - test/features/when_i_run.feature
105
+ has_rdoc: