aruba-turnip 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +4 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +10 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +55 -0
  9. data/Rakefile +6 -0
  10. data/aruba-turnip.gemspec +30 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/aruba/turnip/command.rb +379 -0
  14. data/lib/aruba/turnip/file.rb +223 -0
  15. data/lib/aruba/turnip/placeholders.rb +37 -0
  16. data/lib/aruba/turnip/testing_frameworks.rb +33 -0
  17. data/lib/aruba/turnip/version.rb +5 -0
  18. data/lib/aruba/turnip.rb +13 -0
  19. data/spec/acceptance/fixtures/cli-app/.rspec +4 -0
  20. data/spec/acceptance/fixtures/cli-app/README.md +39 -0
  21. data/spec/acceptance/fixtures/cli-app/Rakefile +1 -0
  22. data/spec/acceptance/fixtures/cli-app/bin/.gitkeep +0 -0
  23. data/spec/acceptance/fixtures/cli-app/cli-app.gemspec +26 -0
  24. data/spec/acceptance/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +15 -0
  25. data/spec/acceptance/fixtures/cli-app/lib/cli/app/version.rb +5 -0
  26. data/spec/acceptance/fixtures/cli-app/lib/cli/app.rb +9 -0
  27. data/spec/acceptance/fixtures/cli-app/spec/acceptance/non-existence.feature +10 -0
  28. data/spec/acceptance/fixtures/cli-app/spec/acceptance/support/env.rb +0 -0
  29. data/spec/acceptance/fixtures/cli-app/spec/spec_helper.rb +17 -0
  30. data/spec/acceptance/fixtures/cli-app/spec/support/aruba.rb +1 -0
  31. data/spec/acceptance/fixtures/cli-app/tmp/aruba/foo/bar/example.txt +1 -0
  32. data/spec/acceptance/steps/aruba_dev_steps.rb +56 -0
  33. data/spec/acceptance/testing_frameworks/turnip/steps/command/exit_statuses.feature +136 -0
  34. data/spec/acceptance/testing_frameworks/turnip/steps/command/run.feature +68 -0
  35. data/spec/acceptance/testing_frameworks/turnip/steps/filesystem/cd_to_directory.feature +33 -0
  36. data/spec/acceptance/testing_frameworks/turnip/steps/filesystem/create_directory.feature +57 -0
  37. data/spec/aruba/turnip_spec.rb +7 -0
  38. data/spec/spec_helper.rb +2 -0
  39. data/spec/turnip_helper.rb +11 -0
  40. metadata +154 -0
@@ -0,0 +1,223 @@
1
+ step 'I use (a/the) fixture named ":name"' do |name|
2
+ copy File.join(aruba.config.fixtures_path_prefix, name), name
3
+ cd name
4
+ end
5
+
6
+ =begin
7
+ step 'I copy (a/the) (file|directory)(?: (?:named|from))? "([^"]*)" to "([^"]*)"' do |file_or_directory, source, destination|
8
+ copy source, destination
9
+ end
10
+
11
+ step 'I move (a/the) (file|directory)(?: (?:named|from))? "([^"]*)" to "([^"]*)"' do |file_or_directory, source, destination|
12
+ move source, destination
13
+ end
14
+
15
+ =end
16
+
17
+ step '(a/the) directory (named) ":dir_name"' do |dir_name|
18
+ create_directory(dir_name)
19
+ end
20
+
21
+ step '(a/the) directory (named) ":dir_name" with mode ":mode"' do |dir_name, dir_mode|
22
+ create_directory(dir_name)
23
+ chmod(dir_mode, dir_name)
24
+ end
25
+
26
+ step '(a/the) file (named) ":file_name" with:' do |file_name, file_content|
27
+ write_file(file_name, file_content)
28
+ end
29
+
30
+ step '(an/the) executable (named) ":file_name" with:' do |file_name, file_content|
31
+ step %(a file named "#{file_name}" with mode "0755" and with:), file_content
32
+ end
33
+
34
+ =begin
35
+ step '(a/the) file (named) "([^"]*)" with "([^"]*)"' do |file_name, file_content|
36
+ write_file(file_name, unescape_text(file_content))
37
+ end
38
+ =end
39
+
40
+ step '(a/the) file (named) ":file_name" with mode ":file_mode" and with:' do |file_name, file_mode, file_content|
41
+ write_file(file_name, unescape_text(file_content))
42
+ chmod(file_mode, file_name)
43
+ end
44
+
45
+ =begin
46
+
47
+ step '(a/the) (\d+) byte file (named) "([^"]*)"' do |file_size, file_name|
48
+ write_fixed_size_file(file_name, file_size.to_i)
49
+ end
50
+
51
+ step '(?:an|the) empty file (named) "([^"]*)"' do |file_name|
52
+ write_file(file_name, "")
53
+ end
54
+
55
+ step '(?:an|the) empty file (named) "([^"]*)" with mode "([^"]*)"' do |file_name, file_mode|
56
+ write_file(file_name, "")
57
+ chmod(file_mode, file_name)
58
+ end
59
+
60
+ step 'I write to "([^"]*)" with:' do |file_name, file_content|
61
+ write_file(file_name, file_content)
62
+ end
63
+
64
+ step 'I overwrite(?: (a/the) file (named))? "([^"]*)" with:' do |file_name, file_content|
65
+ overwrite_file(file_name, file_content)
66
+ end
67
+
68
+ =end
69
+
70
+ step 'I append to ":file_name" with:' do |file_name, file_content|
71
+ append_to_file(file_name, file_content)
72
+ end
73
+
74
+ =begin
75
+
76
+ step 'I append to "([^"]*)" with "([^"]*)"' do |file_name, file_content|
77
+ append_to_file(file_name, file_content)
78
+ end
79
+
80
+ step 'I remove (a/the) (?:file|directory) (named) "([^"]*)"( with full force)?' do |name, force_remove|
81
+ remove(name, :force => force_remove.nil? ? false : true)
82
+ end
83
+
84
+ step '(a/the) (?:file|directory) (named) "([^"]*)" does not exist' do |name|
85
+ remove(name, :force => true)
86
+ end
87
+
88
+ =end
89
+
90
+ step 'I cd to ":dir"' do |dir|
91
+ cd(dir)
92
+ end
93
+
94
+ =begin
95
+
96
+ step 'the following files should (not )?exist:' do |negated, files|
97
+ files = files.raw.flatten
98
+
99
+ if negated
100
+ expect(files).not_to include an_existing_file
101
+ else
102
+ expect(files).to Aruba::Matchers.all be_an_existing_file
103
+ end
104
+ end
105
+
106
+ =end
107
+
108
+ placeholder :file_or_directory do
109
+ match /file/ do
110
+ "file"
111
+ end
112
+
113
+ match /directory/ do
114
+ "directory"
115
+ end
116
+ end
117
+
118
+ step '(a/the) :file_or_directory (named) ":path" :outcome exist (anymore)' do |directory_or_file, path, expect_match|
119
+ case directory_or_file
120
+ when "file"
121
+ if expect_match
122
+ expect(path).to be_an_existing_file
123
+ else
124
+ expect(path).not_to be_an_existing_file
125
+ end
126
+ when "directory"
127
+ if expect_match
128
+ expect(path).to be_an_existing_directory
129
+ else
130
+ expect(path).not_to be_an_existing_directory
131
+ end
132
+ end
133
+ end
134
+
135
+ =begin
136
+
137
+ step '(a/the) file matching %r<(.*?)> should (not )?exist' do |pattern, expect_match|
138
+ if expect_match
139
+ expect(all_paths).not_to include a_file_name_matching(pattern)
140
+ else
141
+ expect(all_paths).to include match a_file_name_matching(pattern)
142
+ end
143
+ end
144
+
145
+ step '(a/the) (\d+) byte file (named) "([^"]*)" should (not )?exist' do |size, file, negated|
146
+ if negated
147
+ expect(file).not_to have_file_size(size)
148
+ else
149
+ expect(file).to have_file_size(size)
150
+ end
151
+ end
152
+
153
+ step 'the following directories should (not )?exist:' do |negated, directories|
154
+ directories = directories.rows.flatten
155
+
156
+ if negated
157
+ expect(directories).not_to include an_existing_directory
158
+ else
159
+ expect(directories).to Aruba::Matchers.all be_an_existing_directory
160
+ end
161
+ end
162
+
163
+ =end
164
+
165
+ step '(a/the) file (named) ":file" :outcome contain ":content"' do |file, expect_success, content|
166
+ if expect_success
167
+ expect(file).to have_file_content file_content_including(content.chomp)
168
+ else
169
+ expect(file).not_to have_file_content file_content_including(content.chomp)
170
+ end
171
+ end
172
+
173
+ =begin
174
+
175
+ step '(a/the) file (named) "([^"]*)" should (not )?contain:' do |file, negated, content|
176
+ if negated
177
+ expect(file).not_to have_file_content file_content_including(content.chomp)
178
+ else
179
+ expect(file).to have_file_content file_content_including(content.chomp)
180
+ end
181
+ end
182
+
183
+ step '(a/the) file (named) "([^"]*)" should (not )?contain exactly:' do |file, negated, content|
184
+ if negated
185
+ expect(file).not_to have_file_content content
186
+ else
187
+ expect(file).to have_file_content content
188
+ end
189
+ end
190
+
191
+ step '(a/the) file (named) "([^"]*)" should (not )?match %r<([^\/]*)>' do |file, negated, content|
192
+ if negated
193
+ expect(file).not_to have_file_content file_content_matching(content)
194
+ else
195
+ expect(file).to have_file_content file_content_matching(content)
196
+ end
197
+ end
198
+
199
+ step '(a/the) file (named) "([^"]*)" should (not )?match \/([^\/]*)\/' do |file, negated, content|
200
+ if negated
201
+ expect(file).not_to have_file_content file_content_matching(content)
202
+ else
203
+ expect(file).to have_file_content file_content_matching(content)
204
+ end
205
+ end
206
+
207
+ step '(a/the) file (named) "([^"]*)" should (not )?be equal to file "([^"]*)"/) do |file, negated, reference_file|
208
+ if negated
209
+ expect(file).not_to have_same_file_content_like(reference_file)
210
+ else
211
+ expect(file).to have_same_file_content_like(reference_file)
212
+ end
213
+ end
214
+
215
+ =end
216
+
217
+ step 'the (file/directory) (named) ":path" :outcome have permissions ":permissions"' do |path, expect_success, permissions|
218
+ if expect_success
219
+ expect(path).to have_permissions(permissions)
220
+ else
221
+ expect(path).not_to have_permissions(permissions)
222
+ end
223
+ end
@@ -0,0 +1,37 @@
1
+ placeholder :channel do
2
+ match /(output|stderr|stdout)/ do |channel|
3
+ channel
4
+ end
5
+ end
6
+
7
+ placeholder :command do
8
+ match /`([^`]+)`/ do |command|
9
+ command
10
+ end
11
+ end
12
+
13
+ placeholder :with_optional_timeout do
14
+ match /\sfor up to (\d+) seconds?/ do |seconds|
15
+ seconds.to_i
16
+ end
17
+
18
+ match // do
19
+ nil
20
+ end
21
+ end
22
+
23
+ placeholder :outcome do
24
+ match /should not/ do
25
+ false
26
+ end
27
+
28
+ match /should/ do
29
+ true
30
+ end
31
+ end
32
+
33
+ placeholder :is_regex do
34
+ match /regex/ do
35
+ true
36
+ end
37
+ end
@@ -0,0 +1,33 @@
1
+ # Turnip
2
+ step "the feature/features :outcome (all) pass" do |expect_success|
3
+ if expect_success
4
+ step 'the output should not contain "(FAILED"'
5
+ step 'the output should not contain "No such step:"'
6
+ step "the exit status should be 0"
7
+ else
8
+ step 'the output should contain "(FAILED"'
9
+ step "the exit status should be 1"
10
+ end
11
+ end
12
+
13
+ # Turnip
14
+ step "the feature/features :outcome (all) pass with:" do |expect_success, string|
15
+ if expect_success
16
+ step "the features should pass"
17
+ else
18
+ step "the features should not pass"
19
+ end
20
+
21
+ step "the output should contain:", string
22
+ end
23
+
24
+ # Turnip
25
+ step "the feature/features :outcome (all) pass with regex:" do |expect_success, string|
26
+ if expect_success
27
+ step "the features should pass"
28
+ else
29
+ step "the features should not pass"
30
+ end
31
+
32
+ step "the output should match %r<#{string}>"
33
+ end
@@ -0,0 +1,5 @@
1
+ module Aruba
2
+ module Turnip
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module Aruba; end
2
+
3
+ module Aruba::Turnip
4
+ end
5
+
6
+ require "turnip/rspec"
7
+ require "aruba/rspec"
8
+ require "aruba/api"
9
+
10
+ require "aruba/turnip/placeholders"
11
+ require "aruba/turnip/command"
12
+ require "aruba/turnip/file"
13
+ require "aruba/turnip/testing_frameworks"
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require turnip/rspec
4
+ --pattern "spec/acceptance/**/*.feature,spec/**/*_spec.rb"
@@ -0,0 +1,39 @@
1
+ # Simple Cli App
2
+
3
+ This is a simple test cli app
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cli-app'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cli-app
20
+
21
+ ## Usage
22
+
23
+ Place files in `lib/cli/app/`. They are loaded automatically. If you need a
24
+ specific load order, use `require` in your files.
25
+
26
+ ### CLI
27
+
28
+ ```
29
+ cli
30
+ ```
31
+
32
+ ### Library
33
+
34
+ You can use `script/console` to load your library.
35
+
36
+ ### Fixture
37
+
38
+ This fixture includes files for `cucumber`- and `rspec`-integration.
39
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
File without changes
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cli/app/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cli-app'
8
+ spec.version = Cli::App::VERSION
9
+ spec.authors = ['Aruba Developers']
10
+ spec.email = 'cukes@googlegroups.com'
11
+
12
+ spec.summary = 'Summary'
13
+ spec.description = 'Description'
14
+ spec.homepage = 'http://example.com'
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.9'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
@@ -0,0 +1,15 @@
1
+ module SimpleCov
2
+ module Formatter
3
+ class HTMLFormatter
4
+ def format(result)
5
+ Dir[File.join(File.dirname(__FILE__), "../public/*")].each do |path|
6
+ FileUtils.cp_r(path, asset_output_path)
7
+ end
8
+
9
+ File.open(File.join(output_path, "index.html"), "wb") do |file|
10
+ file.puts template("layout").result(binding)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Cli
2
+ module App
3
+ VERSION = "0.1.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'cli/app/version'
2
+
3
+ ::Dir.glob(File.expand_path('../**/*.rb', __FILE__)).each { |f| require_relative f }
4
+
5
+ module Cli
6
+ module App
7
+ # Your code goes here...
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ Feature: Working Directory
2
+ Scenario: Working Directory
3
+ Given a file named "foo/bar/example.txt" with:
4
+ """
5
+ hello world
6
+ """
7
+ When I cd to "foo/bar"
8
+ And I run `cat example.txt`
9
+ Then the output should contain "hello world"
10
+ And the file "example.txt" should exist
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
2
+ $LOAD_PATH.unshift File.expand_path("../../../../../lib", __dir__)
3
+
4
+ require "aruba/turnip"
5
+ require "cli/app"
6
+
7
+ RSpec.configure do |config|
8
+ config.include Aruba::Api
9
+ end
10
+
11
+ ::Dir.glob(::File.expand_path("support/**/*.rb", __dir__)).each do |f|
12
+ require_relative f
13
+ end
14
+
15
+ ::Dir.glob(::File.expand_path("acceptance/support/**/*.rb", __dir__)).each do |f|
16
+ require_relative f
17
+ end
@@ -0,0 +1 @@
1
+ require 'aruba/rspec'
@@ -0,0 +1,56 @@
1
+ When /^I do aruba (.*)$/ do |aruba_step|
2
+ @aruba_exception = StandardError.new
3
+
4
+ begin
5
+ step(aruba_step)
6
+ rescue => e
7
+ @aruba_exception = e
8
+ end
9
+ end
10
+
11
+ # Useful for debugging timing problems
12
+ When /^sleep (\d+)$/ do |time|
13
+ sleep time.to_i
14
+ end
15
+
16
+ When /^I set env variable "(\w+)" to "([^"]*)"$/ do |var, value|
17
+ ENV[var] = value
18
+ end
19
+
20
+ Then /^aruba should fail with "([^"]*)"$/ do |error_message|
21
+ expect(@aruba_exception.message).to include sanitize_text(error_message)
22
+ end
23
+
24
+ Then /^the following step should fail with Spec::Expectations::ExpectationNotMetError:$/ do |multiline_step|
25
+ expect{steps multiline_step.to_s}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
26
+ end
27
+
28
+ Given(/^the default executable$/) do
29
+ step 'an executable named "bin/aruba-test-cli" with:', <<-EOS
30
+ #!/usr/bin/env ruby
31
+
32
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
33
+ require 'cli/app'
34
+
35
+ exit 0
36
+ EOS
37
+ end
38
+
39
+ Given(/^the default feature-test$/) do
40
+ step(
41
+ 'a file named "features/default.feature" with:',
42
+ <<-EOS.strip_heredoc
43
+ Feature: Default Feature
44
+
45
+ This is the default feature
46
+
47
+ Scenario: Run command
48
+ Given I successfully run `cli`
49
+ EOS
50
+ )
51
+ end
52
+
53
+ Then(/^aruba should be installed on the local system$/) do
54
+ run('gem list aruba')
55
+ expect(last_command_started).to have_output(/aruba/)
56
+ end
@@ -0,0 +1,136 @@
1
+ Feature: Check exit status of commands
2
+
3
+ Use the `the exit status should be \d`-step to check the exit status of the
4
+ last command which was executed.
5
+
6
+ Background:
7
+ Given I use a fixture named "cli-app"
8
+
9
+ Scenario: Test for exit status of 0
10
+ Given an executable named "bin/aruba-test-cli" with:
11
+ """
12
+ #!/bin/bash
13
+ exit 0
14
+ """
15
+ And a file named "spec/acceptance/exit_status.feature" with:
16
+ """
17
+ Feature: Exit status
18
+ Scenario: Run command
19
+ When I run `aruba-test-cli`
20
+ Then the exit status should be 0
21
+ """
22
+ When I run `rspec`
23
+ Then the features should all pass
24
+
25
+ Scenario: Test for exit status 1
26
+ Given an executable named "bin/aruba-test-cli" with:
27
+ """
28
+ #!/bin/bash
29
+ exit 1
30
+ """
31
+ And a file named "spec/acceptance/exit_status.feature" with:
32
+ """
33
+ Feature: Failing program
34
+ Scenario: Run command
35
+ When I run `aruba-test-cli`
36
+ Then the exit status should be 1
37
+ """
38
+ When I run `rspec`
39
+ Then the features should all pass
40
+
41
+ Scenario: Test for non-zero exit status
42
+ Given an executable named "bin/aruba-test-cli" with:
43
+ """
44
+ #!/bin/bash
45
+ exit 1
46
+ """
47
+ And a file named "spec/acceptance/exit_status.feature" with:
48
+ """
49
+ Feature: Failing program
50
+ Scenario: Run command
51
+ When I run `aruba-test-cli`
52
+ Then the exit status should not be 0
53
+ """
54
+ When I run `rspec`
55
+ Then the features should all pass
56
+
57
+ Scenario: Successfully run something
58
+ Given an executable named "bin/aruba-test-cli" with:
59
+ """
60
+ #!/bin/bash
61
+ exit 0
62
+ """
63
+ And a file named "spec/acceptance/exit_status.feature" with:
64
+ """
65
+ Feature: Failing program
66
+ Scenario: Run command
67
+ When I successfully run `aruba-test-cli`
68
+ """
69
+ When I run `rspec`
70
+ Then the features should all pass
71
+
72
+ Scenario: Fail to run something successfully
73
+ Given an executable named "bin/aruba-test-cli" with:
74
+ """
75
+ #!/bin/bash
76
+ exit 1
77
+ """
78
+ And a file named "spec/acceptance/exit_status.feature" with:
79
+ """
80
+ Feature: Failing program
81
+ Scenario: Run command
82
+ When I successfully run `aruba-test-cli`
83
+ """
84
+ When I run `rspec`
85
+ Then the features should not all pass
86
+
87
+ Scenario: Overwrite the default exit timeout via step
88
+ Given an executable named "bin/aruba-test-cli" with:
89
+ """
90
+ #!/bin/bash
91
+ sleep 1
92
+ """
93
+ And a file named "spec/acceptance/exit_status.feature" with:
94
+ """
95
+ Feature: Failing program
96
+ Scenario: Run command
97
+ Given the default aruba exit timeout is 2 seconds
98
+ When I successfully run `aruba-test-cli`
99
+ """
100
+ When I run `rspec`
101
+ Then the features should all pass
102
+
103
+ Scenario: Successfully run something longer then the default time
104
+ Given an executable named "bin/aruba-test-cli" with:
105
+ """
106
+ #!/bin/bash
107
+ sleep 1
108
+ """
109
+ And a file named "spec/acceptance/exit_status.feature" with:
110
+ """
111
+ Feature: Failing program
112
+ Scenario: Run command
113
+ Given the default aruba exit timeout is 0 seconds
114
+ When I successfully run `aruba-test-cli` for up to 2 seconds
115
+ """
116
+ When I run `rspec`
117
+ Then the features should all pass
118
+
119
+ Scenario: Unsuccessfully run something that takes too long
120
+ Given an executable named "bin/aruba-test-cli" with:
121
+ """
122
+ #!/bin/bash
123
+ sleep 2
124
+ """
125
+ And a file named "spec/acceptance/exit_status.feature" with:
126
+ """
127
+ Feature: Failing program
128
+ Scenario: Run command
129
+ Given the default aruba exit timeout is 0 seconds
130
+ When I successfully run `aruba-test-cli` for up to 1 seconds
131
+ """
132
+ When I run `rspec`
133
+ Then the features should not all pass with:
134
+ """
135
+ expected "aruba-test-cli" to have finished in time
136
+ """