rspec-shell-expectations 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d23f0c4fbf35c8359940dc9c6f4f1e5a35648e00
4
- data.tar.gz: 1494b311ed44a4442d1f0f7bb520f6ea60b6131b
3
+ metadata.gz: 5e9f440ad12bd32b427963ee19bac8917d16fb35
4
+ data.tar.gz: 96b950d92f8a37146454dc0b4ea7b7d56e68a94c
5
5
  SHA512:
6
- metadata.gz: 5c70b05636a175b075ab78d01a13d98e8520adf010ed7779dbaa8de87aa26bd158e05cdf02307fab8b7018422375fe1956b660be48c896e722dc36a5e2035ec0
7
- data.tar.gz: 7b9a2bbbfdfdb29662762b7ba0ae66ce46a86bbe40a62a6008324c8ead69e21f1192415706d5609e882d79f6ec83831f54a70342ea20d1671a26305826579115
6
+ metadata.gz: 8e1a7f3c994ca57c059da3b01506bda96c467bd305d3c9c2d33d1c0f1f035aad4d254f642f393063af0f2cea965920d1f15da60ae62ebee8cf008d15e78c635d
7
+ data.tar.gz: 2b44edac02c0ca132de37eb7cf56e21d7f5c2bffc8426dcb0374ddc6daf6f52ec53611951cd1eabf0919bd4999dc2a79f853f49e7269428a078478e0ff15ddbd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.1.0
2
+
3
+ * Support chaining of arguments in multiple steps
4
+ (`.with_args(...).with_args(...)`
5
+
1
6
  # 1.0.0
2
7
 
3
8
  * Initial release
data/README.md CHANGED
@@ -22,6 +22,19 @@ Or install it yourself as:
22
22
 
23
23
  $ gem install rspec-shell-expectations
24
24
 
25
+
26
+ You can setup rspec-shell-expectations globally for your spec suite:
27
+
28
+ in `spec_helper.rb`:
29
+
30
+ ```ruby
31
+ require 'rspec/shell/expectations'
32
+
33
+ RSpec.configure do |c|
34
+ c.include Rspec::Shell::Expectations
35
+ end
36
+ ```
37
+
25
38
  ## Usage
26
39
 
27
40
  see specs in `spec/` folder:
@@ -29,6 +42,8 @@ see specs in `spec/` folder:
29
42
  ### Running script through stubbed env:
30
43
 
31
44
  ```ruby
45
+ require 'rspec/shell/expectations'
46
+
32
47
  describe 'my shell script' do
33
48
  include Rspec::Shell::Expectations
34
49
 
@@ -48,8 +63,13 @@ see specs in `spec/` folder:
48
63
 
49
64
  ```ruby
50
65
  let(:stubbed_env) { create_stubbed_env }
51
- before do
52
- stubbed_env.stub_command('rake')
66
+ let(:bundle) { stubbed_env.stub_command('bundle') }
67
+ let(:rake) { bundle.with_args('exec', 'rake') }
68
+
69
+ it 'is stubbed' do
70
+ stubbed_env.execute 'my-script.sh'
71
+ expect(rake.with_args('test')).to be_called
72
+ expect(bundle.with_args('install)).to be_called
53
73
  end
54
74
  ```
55
75
 
@@ -0,0 +1,20 @@
1
+ Feature:
2
+ In order to reduce repetition of arguments
3
+ As a developer
4
+ I want to chain arguments seperately
5
+
6
+
7
+ Scenario: Chain arguments
8
+ Given I have the shell script
9
+ """
10
+ #!/bin/bash
11
+ bundle exec rake test
12
+ bundle exec rake build
13
+ """
14
+ And I have stubbed "bundle" with args as "rake":
15
+ | args |
16
+ | exec |
17
+ | rake |
18
+ When I run this script in a simulated environment
19
+ Then the command "rake" is called with "test"
20
+ And the command "rake" is called with "build"
@@ -10,6 +10,15 @@ Given(/^I have stubbed "(.*?)"$/) do |command|
10
10
  @stubbed_command = simulated_environment.stub_command command
11
11
  end
12
12
 
13
+ Given(/^I have stubbed "(.*?)" with args as "(.*)":$/) do |command, call, table|
14
+ # table is a Cucumber::Ast::Table
15
+ args = table.hashes.map { |d| d['args'] }
16
+ @stubbed_command = simulated_environment.stub_command(command)
17
+ .with_args(*args)
18
+ @remembered_commands ||= {}
19
+ @remembered_commands[call] = @stubbed_command
20
+ end
21
+
13
22
  Given(/^I have stubbed "(.*?)" with args:$/) do |command, table|
14
23
  # table is a Cucumber::Ast::Table
15
24
  args = table.hashes.map { |d| d['args'] }
@@ -58,9 +67,10 @@ Then(/^the exitstatus will be (\d+)$/) do |statuscode|
58
67
  expect(@status.exitstatus).to eql statuscode.to_i
59
68
  end
60
69
 
61
- c = /^(the command ".*")/
70
+ c = /^(the command "[^"]+")/
62
71
  Transform(/^the command "(.*)"/) do |command|
63
- simulated_environment.stub_command command
72
+ cmd = (@remembered_commands || {})[command]
73
+ cmd || simulated_environment.stub_command(command)
64
74
  end
65
75
 
66
76
  Then(/#{c} is called$/) do |command|
@@ -7,6 +7,10 @@ module Rspec
7
7
  @config, @call_log, @args = config, call_log, args
8
8
  end
9
9
 
10
+ def with_args(*args)
11
+ StubbedCall.new(@config, @call_log, @args + args)
12
+ end
13
+
10
14
  def returns_exitstatus(statuscode)
11
15
  @config.set_exitcode(statuscode, @args)
12
16
  @config.write
@@ -2,7 +2,7 @@ module Rspec
2
2
  module Shell
3
3
  #:nodoc:
4
4
  module Expectations
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,36 @@
1
+ require 'English'
2
+ require 'rspec/shell/expectations'
3
+
4
+ describe 'Assert called' do
5
+ include Rspec::Shell::Expectations
6
+ let(:stubbed_env) { create_stubbed_env }
7
+ let!(:rake) { stubbed_env.stub_command('bundle').with_args('exec', 'rake') }
8
+
9
+ let(:script) do
10
+ <<-SCRIPT
11
+ bundle exec rake foo:bar
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
+ subject do
26
+ stubbed_env.execute script_path.to_s
27
+ end
28
+
29
+ describe 'assert called' do
30
+ it 'returns called status' do
31
+ subject
32
+ expect(rake.with_args('foo:bar')).to be_called
33
+ expect(rake.with_args('foo')).not_to be_called
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-shell-expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthijs Groen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2014-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,13 +59,14 @@ files:
59
59
  - Rakefile
60
60
  - bin/stub
61
61
  - features/README.md
62
- - features/developer/assert_calls.feature
63
- - features/developer/assert_stdin.feature
64
- - features/developer/change_exitstatus.feature
62
+ - features/developer/assert-calls.feature
63
+ - features/developer/assert-stdin.feature
64
+ - features/developer/chain-arguments.feature
65
+ - features/developer/change-exitstatus.feature
65
66
  - features/developer/provide-env-vars.feature
66
67
  - features/developer/step_definitions/general_steps.rb
67
- - features/developer/stub_commands.feature
68
- - features/developer/stub_output.feature
68
+ - features/developer/stub-commands.feature
69
+ - features/developer/stub-output.feature
69
70
  - features/developer/support/simulated_env.rb
70
71
  - features/developer/support/tempfiles.rb
71
72
  - features/developer/support/workfolder.rb
@@ -79,6 +80,7 @@ files:
79
80
  - rspec-shell-expectations.gemspec
80
81
  - spec/assert_called_spec.rb
81
82
  - spec/assert_stdin_spec.rb
83
+ - spec/chain_args_spec.rb
82
84
  - spec/change_exitstatus_spec.rb
83
85
  - spec/provide_env_vars_spec.rb
84
86
  - spec/replace_shell_commands_spec.rb
@@ -109,18 +111,20 @@ specification_version: 4
109
111
  summary: Fake execution environments to TDD shell scripts
110
112
  test_files:
111
113
  - features/README.md
112
- - features/developer/assert_calls.feature
113
- - features/developer/assert_stdin.feature
114
- - features/developer/change_exitstatus.feature
114
+ - features/developer/assert-calls.feature
115
+ - features/developer/assert-stdin.feature
116
+ - features/developer/chain-arguments.feature
117
+ - features/developer/change-exitstatus.feature
115
118
  - features/developer/provide-env-vars.feature
116
119
  - features/developer/step_definitions/general_steps.rb
117
- - features/developer/stub_commands.feature
118
- - features/developer/stub_output.feature
120
+ - features/developer/stub-commands.feature
121
+ - features/developer/stub-output.feature
119
122
  - features/developer/support/simulated_env.rb
120
123
  - features/developer/support/tempfiles.rb
121
124
  - features/developer/support/workfolder.rb
122
125
  - spec/assert_called_spec.rb
123
126
  - spec/assert_stdin_spec.rb
127
+ - spec/chain_args_spec.rb
124
128
  - spec/change_exitstatus_spec.rb
125
129
  - spec/provide_env_vars_spec.rb
126
130
  - spec/replace_shell_commands_spec.rb