rspec-bash 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +30 -0
  3. data/.travis.yml +1 -0
  4. data/Gemfile +4 -4
  5. data/README.md +87 -77
  6. data/Rakefile +1 -1
  7. data/bin/function_override_wrapper.sh.erb +6 -3
  8. data/bin/stub.rb.erb +56 -0
  9. data/lib/rspec/bash.rb +1 -0
  10. data/lib/rspec/bash/call_configuration.rb +39 -14
  11. data/lib/rspec/bash/call_log.rb +33 -43
  12. data/lib/rspec/bash/matchers/called_with_arguments.rb +7 -2
  13. data/lib/rspec/bash/stubbed_command.rb +22 -14
  14. data/lib/rspec/bash/stubbed_env.rb +15 -16
  15. data/lib/rspec/bash/util.rb +2 -0
  16. data/lib/rspec/bash/util/call_conf_argument_list_matcher.rb +47 -0
  17. data/lib/rspec/bash/util/call_log_argument_list_matcher.rb +33 -0
  18. data/return_exitstatus_spec.rb +14 -0
  19. data/rspec-bash.gemspec +2 -3
  20. data/spec/classes/call_configuration_spec.rb +296 -8
  21. data/spec/classes/call_log_spec.rb +168 -272
  22. data/spec/classes/stub_spec.rb +510 -0
  23. data/spec/classes/stubbed_command_spec.rb +26 -26
  24. data/spec/classes/stubbed_env_spec.rb +58 -64
  25. data/spec/classes/util/call_conf_argument_list_matcher_spec.rb +579 -0
  26. data/spec/classes/util/call_log_argument_list_matcher_spec.rb +211 -0
  27. data/spec/helper/shared_tmpdir.rb +6 -0
  28. data/spec/helper/string_file_io.rb +9 -0
  29. data/spec/integration/call_log/called_with_args_spec.rb +48 -0
  30. data/spec/integration/call_log/called_with_no_args_spec.rb +21 -0
  31. data/spec/integration/call_log/stdin_spec.rb +53 -0
  32. data/spec/integration/matchers/be_called_with_arguments_spec.rb +60 -0
  33. data/spec/integration/matchers/be_called_with_no_arguments_spec.rb +35 -0
  34. data/spec/integration/stubbed_command/outputs_spec.rb +262 -0
  35. data/spec/integration/stubbed_command/returns_exitstatus_spec.rb +99 -0
  36. data/spec/integration/stubbed_env/execute_with_env_vars_spec.rb +17 -0
  37. data/spec/integration/stubbed_env/execute_with_path_spec.rb +34 -0
  38. data/spec/integration/stubbed_env/execute_with_stub_wrapper_spec.rb +23 -0
  39. data/spec/spec_helper.rb +10 -0
  40. metadata +42 -24
  41. data/bin/stub +0 -62
  42. data/spec/integration/assert_called_spec.rb +0 -48
  43. data/spec/integration/assert_stdin_spec.rb +0 -39
  44. data/spec/integration/chain_args_spec.rb +0 -65
  45. data/spec/integration/change_exitstatus_spec.rb +0 -53
  46. data/spec/integration/provide_env_vars_spec.rb +0 -31
  47. data/spec/integration/replace_shell_commands_spec.rb +0 -48
  48. data/spec/integration/stub_output_spec.rb +0 -110
  49. data/spec/matchers/be_called_with_arguments_spec.rb +0 -55
  50. data/spec/matchers/be_called_with_no_arguments_spec.rb +0 -32
@@ -1,110 +0,0 @@
1
- require 'English'
2
- require 'rspec/bash'
3
-
4
- describe 'Stub command output' do
5
- include Rspec::Bash
6
- let(:stubbed_env) { create_stubbed_env }
7
- let!(:command1_stub) { stubbed_env.stub_command('command1') }
8
-
9
- let(:script) do
10
- <<-SCRIPT
11
- command1
12
- SCRIPT
13
- end
14
- let(:script_path) { Pathname.new '/tmp/test_script.sh' }
15
-
16
- before do
17
- script_path.open('w') { |f| f.puts script }
18
- script_path.chmod 0777
19
- end
20
-
21
- after do
22
- script_path.delete
23
- end
24
-
25
- describe 'stubbing standard-out' do
26
- it 'changes standard-out' do
27
- command1_stub.outputs('hello', to: :stdout)
28
- output, error, status = stubbed_env.execute "#{script_path} 2>/dev/null"
29
-
30
- expect(output).to eql 'hello'
31
- expect(error).to be_empty
32
- end
33
- end
34
-
35
- describe 'stubbing standard-err' do
36
- it 'changes standard-out' do
37
- command1_stub.outputs('world', to: :stderr)
38
- output, error, status = stubbed_env.execute "#{script_path} 1>/dev/null"
39
- expect(error).to eql "world\n"
40
- expect(output).to be_empty
41
- end
42
- end
43
-
44
- describe 'stubbing contents to file' do
45
- let(:filename) { 'test-log.nice' }
46
- after do
47
- f = Pathname.new(filename)
48
- f.delete if f.exist?
49
- end
50
-
51
- it 'write data to a file' do
52
- command1_stub.outputs('world', to: filename)
53
- output, error, status = stubbed_env.execute "#{script_path}"
54
-
55
- expect(error).to be_empty
56
- expect(output).to be_empty
57
- expect(Pathname.new(filename).read).to eql 'world'
58
- end
59
-
60
- describe 'using passed argument as filename' do
61
- let(:script) do
62
- <<-SCRIPT
63
- command1 input output
64
- SCRIPT
65
- end
66
-
67
- let(:passed_filename) { ['hello-', :arg2, '.foo'] }
68
- let(:filename) { 'hello-output.foo' }
69
-
70
- it 'writes data to an interpolated filename' do
71
- command1_stub.outputs('world', to: passed_filename)
72
- stubbed_env.execute "#{script_path}"
73
-
74
- expect(Pathname.new(filename).read).to eql 'world'
75
- end
76
- end
77
- end
78
-
79
- describe 'stubbing commands with arguments passed to stdout' do
80
- let(:script) do
81
- <<-SCRIPT
82
- command1 input output
83
- SCRIPT
84
- end
85
-
86
- it 'outputs correctly when all arguments match' do
87
- command1_stub.with_args('input', 'output').outputs('world', to: :stdout)
88
- output, error, status = stubbed_env.execute "#{script_path}"
89
-
90
- expect(error).to be_empty
91
- expect(output).to eql 'world'
92
- end
93
-
94
- it 'does not output when called with extra arguments, even if some match' do
95
- command1_stub.with_args('input', 'output', 'anything').outputs('arbitrary string', to: :stdout)
96
- output, error, status = stubbed_env.execute "#{script_path}"
97
-
98
- expect(error).to be_empty
99
- expect(output).to be_empty
100
- end
101
-
102
- it 'does not output when called with only one matching argument out of many' do
103
- command1_stub.with_args('input').outputs('arbitrary string', to: :stdout)
104
- output, error, status = stubbed_env.execute "#{script_path}"
105
-
106
- expect(error).to be_empty
107
- expect(output).to be_empty
108
- end
109
- end
110
- end
@@ -1,55 +0,0 @@
1
- require 'English'
2
- require 'rspec/bash'
3
-
4
- # TODO - the below specs test implementation, until the goofy wiring of StubbedCommand => StubbedCall => CallLog is sorted out
5
-
6
- describe 'be_called_with_arguments' do
7
- include Rspec::Bash
8
- let(:stubbed_env) { create_stubbed_env }
9
-
10
- context 'with a command' do
11
- context 'and no chain calls' do
12
- before(:each) do
13
- @command = stubbed_env.stub_command('stubbed_command')
14
- @actual_stdout, @actual_stderr, @actual_status = stubbed_env.execute_inline(<<-multiline_script
15
- stubbed_command first_argument second_argument
16
- multiline_script
17
- )
18
- end
19
- it 'correctly identifies the called arguments' do
20
- expect(@command).to be_called_with_arguments('first_argument', 'second_argument')
21
- end
22
- it 'correctly matches when wildcard is used for first argument' do
23
- expect(@command).to be_called_with_arguments(anything, 'second_argument')
24
- end
25
- it 'correctly matches when wildcard is used for second argument' do
26
- expect(@command).to be_called_with_arguments('first_argument', anything)
27
- end
28
- it 'correctly matches when wildcard is used for all arguments' do
29
- expect(@command).to be_called_with_arguments(anything, anything)
30
- end
31
- end
32
- context 'and the times chain call' do
33
- before(:each) do
34
- @command = stubbed_env.stub_command('stubbed_command')
35
- @actual_stdout, @actual_stderr, @actual_status = stubbed_env.execute_inline(<<-multiline_script
36
- stubbed_command duplicated_argument once_called_argument
37
- stubbed_command duplicated_argument irrelevant_argument
38
- multiline_script
39
- )
40
- end
41
- it 'matches when arguments are called twice' do
42
- expect(@command).to be_called_with_arguments('duplicated_argument', anything).times(2)
43
- end
44
- it 'matches when argument is called once' do
45
- expect(@command).to be_called_with_arguments(anything, 'once_called_argument').times(1)
46
- end
47
- it 'matches when argument combination is called once' do
48
- expect(@command).to be_called_with_arguments('duplicated_argument', 'once_called_argument').times(1)
49
- end
50
- it 'matches when argument is not called' do
51
- expect(@command).to_not be_called_with_arguments('not_called_argument').times(1)
52
- end
53
- end
54
- end
55
- end
@@ -1,32 +0,0 @@
1
- require 'English'
2
- require 'rspec/bash'
3
-
4
- describe 'be_called_with_no_arguments' do
5
- include Rspec::Bash
6
- let(:stubbed_env) { create_stubbed_env }
7
-
8
- context 'when command is called with no args' do
9
- before(:each) do
10
- @command = stubbed_env.stub_command('stubbed_command')
11
- @actual_stdout, @actual_stderr, @actual_status = stubbed_env.execute_inline(<<-multiline_script
12
- stubbed_command
13
- multiline_script
14
- )
15
- end
16
- it 'correctly identifies that no arguments were called' do
17
- expect(@command).to be_called_with_no_arguments
18
- end
19
- end
20
- context 'when command is called with args' do
21
- before(:each) do
22
- @command = stubbed_env.stub_command('stubbed_command')
23
- @actual_stdout, @actual_stderr, @actual_status = stubbed_env.execute_inline(<<-multiline_script
24
- stubbed_command argument
25
- multiline_script
26
- )
27
- end
28
- it 'correctly identifies that arguments were passed into command call' do
29
- expect(@command).to_not be_called_with_no_arguments
30
- end
31
- end
32
- end