aruba 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +167 -3
  4. data/.simplecov +32 -0
  5. data/.travis.yml +5 -2
  6. data/.yardopts +8 -0
  7. data/CONTRIBUTING.md +18 -8
  8. data/Gemfile +25 -0
  9. data/History.md +8 -0
  10. data/README.md +80 -18
  11. data/Rakefile +1 -1
  12. data/aruba.gemspec +6 -8
  13. data/cucumber.yml +5 -6
  14. data/features/debug.feature +15 -0
  15. data/features/file_system_commands.feature +14 -2
  16. data/features/fixtures/copy/file.txt +1 -0
  17. data/features/fixtures/fixtures-app/test.txt +1 -0
  18. data/features/fixtures/spawn_process/stderr.sh +3 -0
  19. data/features/interactive.feature +2 -2
  20. data/features/step_definitions/aruba_dev_steps.rb +1 -1
  21. data/features/support/custom_main.rb +10 -6
  22. data/features/support/env.rb +27 -2
  23. data/features/support/simplecov_setup.rb +8 -0
  24. data/lib/aruba.rb +2 -2
  25. data/lib/aruba/announcer.rb +161 -0
  26. data/lib/aruba/api.rb +490 -251
  27. data/lib/aruba/config.rb +0 -1
  28. data/lib/aruba/cucumber.rb +71 -59
  29. data/lib/aruba/cucumber/hooks.rb +18 -13
  30. data/lib/aruba/errors.rb +6 -0
  31. data/lib/aruba/in_process.rb +5 -45
  32. data/lib/aruba/matchers/command.rb +79 -0
  33. data/lib/aruba/matchers/directory.rb +59 -0
  34. data/lib/aruba/matchers/file.rb +177 -0
  35. data/lib/aruba/matchers/mode.rb +52 -0
  36. data/lib/aruba/matchers/path.rb +99 -0
  37. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +21 -1
  38. data/lib/aruba/process_monitor.rb +113 -0
  39. data/lib/aruba/processes/basic_process.rb +25 -0
  40. data/lib/aruba/processes/debug_process.rb +59 -0
  41. data/lib/aruba/processes/in_process.rb +86 -0
  42. data/lib/aruba/processes/spawn_process.rb +159 -0
  43. data/lib/aruba/reporting.rb +2 -2
  44. data/lib/aruba/rspec.rb +26 -0
  45. data/lib/aruba/spawn_process.rb +5 -104
  46. data/lib/aruba/utils.rb +21 -0
  47. data/script/bootstrap +22 -0
  48. data/script/console +17 -0
  49. data/script/test +3 -0
  50. data/spec/aruba/api_spec.rb +813 -147
  51. data/spec/aruba/hooks_spec.rb +0 -1
  52. data/spec/aruba/matchers/command_spec.rb +43 -0
  53. data/spec/aruba/matchers/directory_spec.rb +58 -0
  54. data/spec/aruba/matchers/file_spec.rb +131 -0
  55. data/spec/aruba/matchers/path_spec.rb +85 -0
  56. data/spec/aruba/spawn_process_spec.rb +46 -28
  57. data/spec/spec_helper.rb +18 -13
  58. data/{config/rubocop/include.yml → spec/support/configs/.keep} +0 -0
  59. data/spec/support/configs/rspec.rb +15 -0
  60. data/spec/support/helpers/.keep +0 -0
  61. data/spec/support/helpers/reporting.rb +44 -0
  62. data/spec/support/matchers/.keep +0 -0
  63. data/spec/support/shared_contexts/.keep +0 -0
  64. data/spec/support/shared_contexts/aruba.rb +45 -0
  65. data/spec/support/shared_examples/.keep +0 -0
  66. data/spec/support/shared_examples/directory.rb +7 -0
  67. data/spec/support/shared_examples/file.rb +7 -0
  68. data/templates/js/jquery-1.11.3.min.js +5 -0
  69. data/templates/main.erb +1 -1
  70. metadata +87 -96
  71. data/config/rubocop/exclude.yml +0 -160
  72. data/templates/js/jquery-1.6.1.min.js +0 -18
@@ -14,5 +14,4 @@ describe Aruba::Hooks do
14
14
  subject.execute :hook_label, self, 1, 2, 3
15
15
  expect(hook_values).to eq [1,2,3]
16
16
  end
17
-
18
17
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Command Matchers' do
4
+ include_context 'uses aruba API'
5
+
6
+ def expand_path(*args)
7
+ @aruba.expand_path(*args)
8
+ end
9
+
10
+ def announcer(*args)
11
+ @aruba.send(:announcer, *args)
12
+ end
13
+
14
+ describe '#to_have_exit_status' do
15
+ let(:cmd) { 'true' }
16
+
17
+ before(:each) { run(cmd) }
18
+
19
+ context 'when has exit 0' do
20
+ it { expect(last_command).to have_exit_status 0 }
21
+ end
22
+
23
+ context 'when has exit 0' do
24
+ let(:cmd) { 'false' }
25
+ it { expect(last_command).not_to have_exit_status 0 }
26
+ end
27
+ end
28
+
29
+ describe '#to_be_successfully_executed_' do
30
+ let(:cmd) { 'true' }
31
+
32
+ before(:each) { run(cmd) }
33
+
34
+ context 'when has exit 0' do
35
+ it { expect(last_command).to be_successfully_executed }
36
+ end
37
+
38
+ context 'when has exit 0' do
39
+ let(:cmd) { 'false' }
40
+ it { expect(last_command).not_to be_successfully_executed }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Directory Matchers' do
4
+ include_context 'uses aruba API'
5
+
6
+ def expand_path(*args)
7
+ @aruba.expand_path(*args)
8
+ end
9
+
10
+ describe 'to_be_existing_directory' do
11
+ let(:name) { 'test.d' }
12
+ let(:path) { File.join(@aruba.current_directory, name) }
13
+
14
+ context 'when directory exists' do
15
+ before :each do
16
+ FileUtils.mkdir_p path
17
+ end
18
+
19
+ it { expect(name).to be_existing_directory }
20
+ end
21
+
22
+ context 'when directory does not exist' do
23
+ it { expect(name).not_to be_existing_directory }
24
+ end
25
+ end
26
+
27
+ describe 'to_have_sub_directory' do
28
+ let(:name) { 'test.d' }
29
+ let(:path) { File.join(@aruba.current_directory, name) }
30
+ let(:content) { %w(subdir.1.d subdir.2.d) }
31
+
32
+ context 'when directory exists' do
33
+ before :each do
34
+ FileUtils.mkdir_p path
35
+ end
36
+
37
+ before :each do
38
+ Array(content).each { |p| Dir.mkdir File.join(path, p) }
39
+ end
40
+
41
+ context 'when single directory' do
42
+ it { expect(name).to have_sub_directory('subdir.1.d') }
43
+ end
44
+
45
+ context 'when multiple directories' do
46
+ it { expect(name).to have_sub_directory(['subdir.1.d', 'subdir.2.d']) }
47
+ end
48
+
49
+ context 'when non existing directory' do
50
+ it { expect(name).not_to have_sub_directory('subdir.3.d') }
51
+ end
52
+ end
53
+
54
+ context 'when directory does not exist' do
55
+ it { expect(name).not_to have_sub_directory('subdir') }
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'File Matchers' do
4
+ include_context 'uses aruba API'
5
+ include_context 'needs to expand paths'
6
+
7
+ describe 'to_be_existing_file' do
8
+ let(:name) { @file_name }
9
+
10
+ context 'when file exists' do
11
+ before(:each) { create_test_files(name) }
12
+
13
+ it { expect(name).to be_existing_file }
14
+ end
15
+
16
+ context 'when file does not exist' do
17
+ it { expect(name).not_to be_existing_file }
18
+ end
19
+ end
20
+
21
+ describe 'to_be_existing_files' do
22
+ let(:name) { %w(file1.txt file2.txt) }
23
+
24
+ context 'when files exists' do
25
+ before(:each) { create_test_files(name) }
26
+
27
+ context 'when list of files is given' do
28
+ it { expect(name).to be_existing_files }
29
+ end
30
+
31
+ context 'when no list of files is given' do
32
+ let(:name) { 'file1.txt' }
33
+ it { expect(name).not_to be_existing_files }
34
+ end
35
+ end
36
+
37
+ context 'when file does not exist' do
38
+ it { expect(name).not_to be_existing_files }
39
+ end
40
+ end
41
+
42
+ describe 'to_have_file_content' do
43
+ context 'when file exists' do
44
+ before :each do
45
+ File.write(@file_path, 'aba')
46
+ end
47
+
48
+ context 'and file content is exactly equal string ' do
49
+ it { expect(@file_name).to have_file_content('aba') }
50
+ end
51
+
52
+ context 'and file content contains string' do
53
+ it { expect(@file_name).to have_file_content(/b/) }
54
+ end
55
+
56
+ context 'and file content is not exactly equal string' do
57
+ it { expect(@file_name).not_to have_file_content('c') }
58
+ end
59
+
60
+ context 'and file content not contains string' do
61
+ it { expect(@file_name).not_to have_file_content(/c/) }
62
+ end
63
+
64
+ context 'when other matchers is given which matches a string start with "a"' do
65
+ it { expect(@file_name).to have_file_content(a_string_starting_with('a')) }
66
+ end
67
+ end
68
+
69
+ context 'when file does not exist' do
70
+ it { expect(@file_name).not_to have_file_content('a') }
71
+ end
72
+
73
+ describe "description" do
74
+ context "when string" do
75
+ it { expect(have_file_content("a").description).to eq('have file content: "a"') }
76
+ end
77
+
78
+ context "when regexp" do
79
+ it { expect(have_file_content(/a/).description).to eq('have file content: /a/') }
80
+ end
81
+
82
+ context "when matcher" do
83
+ it { expect(have_file_content(a_string_starting_with "a").description).to eq('have file content: a string starting with "a"') }
84
+ end
85
+ end
86
+
87
+ describe 'failure messages' do
88
+ def fail_with(message)
89
+ raise_error(RSpec::Expectations::ExpectationNotMetError, message)
90
+ end
91
+
92
+ example 'for a string' do
93
+ expect do
94
+ expect(@file_name).to have_file_content("z")
95
+ end.to fail_with('expected "test.txt" to have file content: "z"')
96
+ end
97
+
98
+ example 'for a string' do
99
+ expect do
100
+ expect(@file_name).to have_file_content(/z/)
101
+ end.to fail_with('expected "test.txt" to have file content: /z/')
102
+ end
103
+
104
+ example 'for a matcher' do
105
+ expect do
106
+ expect(@file_name).to have_file_content(a_string_starting_with "z")
107
+ end.to fail_with('expected "test.txt" to have file content: a string starting with "z"')
108
+ end
109
+ end
110
+ end
111
+
112
+ describe 'to_have_file_size' do
113
+ context 'when file exists' do
114
+ before :each do
115
+ File.write(@file_path, '')
116
+ end
117
+
118
+ context 'and file size is equal' do
119
+ it { expect(@file_name).to have_file_size(0) }
120
+ end
121
+
122
+ context 'and file size is not equal' do
123
+ it { expect(@file_name).not_to have_file_size(1) }
124
+ end
125
+ end
126
+
127
+ context 'when file does not exist' do
128
+ it { expect(@file_name).not_to have_file_size(0) }
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Path Matchers' do
4
+ include_context 'uses aruba API'
5
+
6
+ def expand_path(*args)
7
+ @aruba.expand_path(*args)
8
+ end
9
+
10
+ describe 'to_match_path_pattern' do
11
+ context 'when pattern is string' do
12
+ context 'when there is file which matches path pattern' do
13
+ before :each do
14
+ File.write(@file_path, '')
15
+ end
16
+
17
+ it { expect(all_paths).to match_path_pattern(expand_path(@file_name)) }
18
+ end
19
+
20
+ context 'when there is not file which matches path pattern' do
21
+ it { expect(all_paths).not_to match_path_pattern('test') }
22
+ end
23
+ end
24
+
25
+ context 'when pattern is regex' do
26
+ context 'when there is file which matches path pattern' do
27
+ before :each do
28
+ File.write(@file_path, '')
29
+ end
30
+
31
+ it { expect(all_paths).to match_path_pattern(/test/) }
32
+ end
33
+
34
+ context 'when there is not file which matches path pattern' do
35
+ it { expect(all_paths).not_to match_path_pattern(/test/) }
36
+ end
37
+ end
38
+ end
39
+
40
+ describe 'to_be_absolute_path' do
41
+ let(:name) { @file_name }
42
+ let(:path) { File.expand_path(File.join(@aruba.current_directory, name)) }
43
+
44
+ context 'when is absolute path' do
45
+ it { expect(path).to be_absolute_path }
46
+ end
47
+
48
+ context 'when is relative path' do
49
+ it { expect(name).not_to be_absolute_path }
50
+ end
51
+ end
52
+
53
+ describe 'to_be_existing_path' do
54
+ context 'when file' do
55
+ context 'exists' do
56
+ before :each do
57
+ File.write(@file_path, '')
58
+ end
59
+
60
+ it { expect(@file_name).to be_existing_path }
61
+ end
62
+
63
+ context 'does not exist' do
64
+ it { expect(@file_name).not_to be_existing_path }
65
+ end
66
+ end
67
+
68
+ context 'when directory' do
69
+ let(:name) { 'test.d' }
70
+ let(:path) { File.join(@aruba.current_directory, name) }
71
+
72
+ context 'exists' do
73
+ before :each do
74
+ FileUtils.mkdir_p path
75
+ end
76
+
77
+ it { expect(name).to be_existing_path }
78
+ end
79
+
80
+ context 'does not exist' do
81
+ it { expect(name).not_to be_existing_path }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,45 +1,63 @@
1
- require 'aruba/spawn_process'
1
+ require 'aruba/processes/spawn_process'
2
2
 
3
- module Aruba
4
- describe SpawnProcess do
3
+ RSpec.describe Aruba::Processes::SpawnProcess do
4
+ subject(:process) { described_class.new(command, exit_timeout, io_wait, working_directory) }
5
5
 
6
- let(:process) { SpawnProcess.new('echo "yo"', 0.1, 0.1) }
6
+ let(:command) { 'echo "yo"' }
7
+ let(:exit_timeout) { 1 }
8
+ let(:io_wait) { 1 }
9
+ let(:working_directory) { Dir.getwd }
7
10
 
8
- describe "#stdout" do
9
- before { process.run! }
11
+ describe "#stdout" do
12
+ before(:each) { process.run! }
10
13
 
11
- it "returns the stdout" do
12
- expect(process.stdout).to eq "yo\n"
13
- end
14
+ context 'when invoked once' do
15
+ it { expect(process.stdout).to eq "yo\n" }
16
+ end
17
+
18
+ context 'when invoked twice' do
19
+ it { 2.times { expect(process.stdout).to eq "yo\n" } }
20
+ end
21
+ end
22
+
23
+ describe "#stderr" do
24
+ let(:command) { 'features/fixtures/spawn_process/stderr.sh yo' }
25
+
26
+ before(:each) { process.run! }
14
27
 
15
- it "returns all the stdout, every time you call it" do
16
- expect(process.stdout).to eq "yo\n"
17
- expect(process.stdout).to eq "yo\n"
18
- end
28
+ context 'when invoked once' do
29
+ it { expect(process.stderr).to eq "yo\n" }
30
+ end
19
31
 
32
+ context 'when invoked twice' do
33
+ it { 2.times { expect(process.stderr).to eq "yo\n" } }
20
34
  end
35
+ end
21
36
 
22
- describe "#stop" do
23
- before { process.run! }
37
+ describe "#stop" do
38
+ let(:reader) { double('reader') }
24
39
 
25
- it "sends any output to the reader" do
26
- reader = double( 'null_object' )
27
- allow( reader ).to receive( :stderr )
28
- expect( reader ).to receive( :stdout ).with("yo\n")
40
+ before(:each) { process.run! }
29
41
 
30
- process.stop(reader)
31
- end
42
+ before :each do
43
+ allow(reader).to receive(:stderr)
44
+ expect(reader).to receive(:stdout).with("yo\n")
32
45
  end
33
46
 
34
- describe "#run!" do
35
- context "upon process launch error" do
36
- let(:process_failure) { SpawnProcess.new('does_not_exists', 1, 1) }
47
+ context 'when stopped successfully' do
48
+ it { process.stop(reader) }
49
+ end
50
+ end
37
51
 
38
- it "raises a Aruba::LaunchError" do
39
- expect{process_failure.run!}.to raise_error(::Aruba::LaunchError)
40
- end
41
- end
52
+ describe "#run!" do
53
+ context "when process run succeeds" do
54
+ it { expect { process.run! }.not_to raise_error }
42
55
  end
43
56
 
57
+ context "when process run fails" do
58
+ let(:command) { 'does_not_exists' }
59
+
60
+ it { expect {process.run!}.to raise_error Aruba::LaunchError }
61
+ end
44
62
  end
45
63
  end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,18 @@
1
- require 'rspec/core'
2
- require 'aruba/api'
3
-
4
- RSpec.configure do |config|
5
- config.filter_run :focus => true
6
- config.run_all_when_everything_filtered = true
7
- config.expect_with :rspec do |c|
8
- c.syntax = :expect
9
- end
10
-
11
- config.include Aruba::Api
12
- config.before(:each) { clean_current_dir }
13
- end
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << ::File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'simplecov'
6
+ SimpleCov.command_name 'rspec'
7
+ SimpleCov.start
8
+
9
+ # Pull in all of the gems including those in the `test` group
10
+ require 'bundler'
11
+ Bundler.require
12
+
13
+ # Loading support files
14
+ Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
15
+ Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
16
+
17
+ # Avoid writing "describe LocalPac::MyClass do [..]" but "describe MyClass do [..]"
18
+ include Aruba