producer-core 0.1.4 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9dca497744fe5fa26c09753548310eb42414a25
4
- data.tar.gz: 212301a43272758c9624d5e0d2556ced790c17b3
3
+ metadata.gz: 2806c20d86e7d0aa08f72a3005b5ee5456cad346
4
+ data.tar.gz: 4c75c67cd9815e30849302aeb9021dcbaf4721a7
5
5
  SHA512:
6
- metadata.gz: 7f456c2225b377db0d58df63d3207fce98a103d18501a0d30969fc75c243c094888ba667dfa109cfb1aef878243fa161a5e800dfe0941bfda7c98dd760bce8ee
7
- data.tar.gz: e4eb9ce9cc707064a9318b0971971231ef9a42279b5f17d9038bb99d2e1d6ae9ec84eccd1b1e4d67486163eb86e817a24bddeeb756bf51376d30b9badf662585
6
+ metadata.gz: 4cddfc09e41207a5d9f01a9e04bac5c7ec7f841e89ce1e225d073923e5555460461b92f93b2978508c1003d8bdd24c92f9f106e947226190ca165ef78ae10b75
7
+ data.tar.gz: 3bace5c3bbba48e3727e380f96d5f4a31f11fd29e9a319a7c09b2e284c400c2b105352bca4b3ae4ebfcabb5159faba99b9d88fa4e47153dfd4ff747b92b70d92
@@ -0,0 +1,44 @@
1
+ @sshd
2
+ Feature: negated test prefix (no_)
3
+
4
+ Scenario: prefixed test fails when non-prefixed test is successful
5
+ Given a recipe with:
6
+ """
7
+ target 'some_host.test'
8
+
9
+ task :successful_test do
10
+ condition { has_env :shell }
11
+
12
+ echo 'successful_test'
13
+ end
14
+
15
+ task :negated_test do
16
+ condition { no_has_env :shell }
17
+
18
+ echo 'negated_test'
19
+ end
20
+ """
21
+ When I successfully execute the recipe
22
+ Then the output must contain "successful_test"
23
+ And the output must not contain "negated_test"
24
+
25
+ Scenario: prefixed test fails when non-prefixed test is failing
26
+ Given a recipe with:
27
+ """
28
+ target 'some_host.test'
29
+
30
+ task :failing_test do
31
+ condition { has_env :inexistent_var }
32
+
33
+ echo 'failing_test'
34
+ end
35
+
36
+ task :negated_test do
37
+ condition { no_has_env :inexistent_var }
38
+
39
+ echo 'negated_test'
40
+ end
41
+ """
42
+ When I successfully execute the recipe
43
+ Then the output must not contain "failing_test"
44
+ And the output must contain "negated_test"
@@ -14,7 +14,7 @@ module Producer
14
14
 
15
15
  def met?
16
16
  return !!@return_value if @tests.empty?
17
- @tests.each { |t| return false unless t.success? }
17
+ @tests.each { |t| return false unless t.pass? }
18
18
  true
19
19
  end
20
20
 
@@ -13,6 +13,9 @@ module Producer
13
13
  define_method(keyword) do |*args|
14
14
  @tests << klass.new(@env, *args)
15
15
  end
16
+ define_method("no_#{keyword}") do |*args|
17
+ @tests << klass.new(@env, *args, negated: true)
18
+ end
16
19
  end
17
20
  end
18
21
 
@@ -3,9 +3,18 @@ module Producer
3
3
  class Test
4
4
  attr_reader :env, :arguments
5
5
 
6
- def initialize(env, *arguments)
6
+ def initialize(env, *arguments, negated: false)
7
7
  @env = env
8
8
  @arguments = arguments
9
+ @negated = negated
10
+ end
11
+
12
+ def negated?
13
+ @negated
14
+ end
15
+
16
+ def pass?
17
+ verify ^ negated?
9
18
  end
10
19
  end
11
20
  end
@@ -2,7 +2,7 @@ module Producer
2
2
  module Core
3
3
  module Tests
4
4
  class HasEnv < Test
5
- def success?
5
+ def verify
6
6
  env.remote.environment.has_key? arguments.first.to_s.upcase
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Producer
2
2
  module Core
3
3
  module Tests
4
4
  class HasFile < Test
5
- def success?
5
+ def verify
6
6
  env.remote.fs.has_file? arguments.first
7
7
  end
8
8
  end
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Core
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
  end
5
5
  end
@@ -2,15 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  module Producer::Core
4
4
  describe Actions::Echo do
5
- let(:env) { Env.new }
5
+ let(:env) { double 'env' }
6
6
  let(:text) { 'hello' }
7
7
  subject(:echo) { Actions::Echo.new(env, text) }
8
8
 
9
9
  describe '#apply' do
10
- before do
11
- env.output = StringIO.new
12
- end
13
-
14
10
  it 'outputs the string given as argument through env.output' do
15
11
  expect(env).to receive(:output).with(text)
16
12
  echo.apply
@@ -8,9 +8,7 @@ module Producer::Core
8
8
  subject(:sh) { Actions::ShellCommand.new(env, command) }
9
9
 
10
10
  describe '#apply' do
11
- before do
12
- env.output = StringIO.new
13
- end
11
+ before { env.output = StringIO.new }
14
12
 
15
13
  it 'delegates the call to env.remote.execute method' do
16
14
  expect(env.remote).to receive(:execute).with(command)
@@ -5,7 +5,7 @@ module Producer::Core
5
5
  include ExitHelpers
6
6
  include FixturesHelpers
7
7
 
8
- let(:recipe_file) { fixture_path_for('recipes/empty.rb') }
8
+ let(:recipe_file) { fixture_path_for 'recipes/empty.rb' }
9
9
  let(:arguments) { [recipe_file] }
10
10
  subject(:cli) { CLI.new(arguments) }
11
11
 
@@ -23,13 +23,13 @@ module Producer::Core
23
23
 
24
24
  describe '#run!' do
25
25
  it 'checks the arguments' do
26
- expect(cli).to receive(:check_arguments!)
26
+ expect(cli).to receive :check_arguments!
27
27
  cli.run!
28
28
  end
29
29
 
30
30
  it 'processes the tasks with the interpreter' do
31
31
  allow(cli.recipe).to receive(:tasks) { [:some_task] }
32
- expect(cli.interpreter).to receive(:process).with([:some_task])
32
+ expect(cli.interpreter).to receive(:process).with [:some_task]
33
33
  cli.run!
34
34
  end
35
35
  end
@@ -61,12 +61,12 @@ module Producer::Core
61
61
 
62
62
  describe '#env' do
63
63
  it 'builds an environment with the current recipe' do
64
- expect(Env).to receive(:new)
64
+ expect(Env).to receive :new
65
65
  cli.env
66
66
  end
67
67
 
68
68
  it 'returns the env' do
69
- env = double('env')
69
+ env = double 'env'
70
70
  allow(Env).to receive(:new) { env }
71
71
  expect(cli.env).to be env
72
72
  end
@@ -88,12 +88,12 @@ module Producer::Core
88
88
 
89
89
  describe '#interpreter' do
90
90
  it 'builds a interpreter' do
91
- expect(Interpreter).to receive(:new)
91
+ expect(Interpreter).to receive :new
92
92
  cli.interpreter
93
93
  end
94
94
 
95
95
  it 'returns the interpreter' do
96
- interpreter = double('interpreter')
96
+ interpreter = double 'interpreter'
97
97
  allow(Interpreter).to receive(:new) { interpreter }
98
98
  expect(cli.interpreter).to be interpreter
99
99
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module Producer::Core
4
4
  describe Condition::DSL do
5
5
  let(:block) { proc { :some_condition_code } }
6
- let(:env) { double('env') }
6
+ let(:env) { double 'env' }
7
7
  subject(:dsl) { Condition::DSL.new(env, &block) }
8
8
 
9
9
  %w[has_env has_file].each do |test|
@@ -22,7 +22,7 @@ module Producer::Core
22
22
  it 'evaluates the DSL sandbox code' do
23
23
  dsl = double('dsl').as_null_object
24
24
  allow(Condition::DSL).to receive(:new) { dsl }
25
- expect(dsl).to receive(:evaluate)
25
+ expect(dsl).to receive :evaluate
26
26
  Condition::DSL.evaluate(env, &block)
27
27
  end
28
28
 
@@ -33,22 +33,24 @@ module Producer::Core
33
33
  end
34
34
 
35
35
  it 'returns the condition' do
36
- condition = double('task')
36
+ condition = double 'task'
37
37
  allow(Condition).to receive(:new) { condition }
38
38
  expect(Condition::DSL.evaluate(env, &block)).to be condition
39
39
  end
40
40
  end
41
41
 
42
42
  describe '.define_test' do
43
- let(:some_test_class) { double('SomeTest class') }
43
+ let(:some_test_class) { double 'SomeTest class' }
44
44
 
45
- before do
46
- Condition::DSL.define_test(:some_test, some_test_class)
47
- end
45
+ before { Condition::DSL.define_test(:some_test, some_test_class) }
48
46
 
49
47
  it 'defines a new test keyword' do
50
48
  expect(dsl).to respond_to :some_test
51
49
  end
50
+
51
+ it 'defines the negated test' do
52
+ expect(dsl).to respond_to :no_some_test
53
+ end
52
54
  end
53
55
 
54
56
  describe '#initialize' do
@@ -78,12 +80,10 @@ module Producer::Core
78
80
  end
79
81
 
80
82
  context 'when a defined test keyword is called' do
81
- let(:some_test_class) { double('SomeTest class') }
83
+ let(:some_test_class) { double 'SomeTest class' }
82
84
  let(:block) { proc { some_test :some, :args } }
83
85
 
84
- before do
85
- Condition::DSL.define_test(:some_test, some_test_class)
86
- end
86
+ before { Condition::DSL.define_test(:some_test, some_test_class) }
87
87
 
88
88
  it 'builds a new test with the env and given arguments' do
89
89
  expect(some_test_class).to receive(:new).with(env, :some, :args)
@@ -91,11 +91,21 @@ module Producer::Core
91
91
  end
92
92
 
93
93
  it 'registers the new test' do
94
- some_test = double('SomeTest instance')
94
+ some_test = double 'SomeTest instance'
95
95
  allow(some_test_class).to receive(:new) { some_test }
96
96
  dsl.evaluate
97
97
  expect(dsl.tests).to include(some_test)
98
98
  end
99
+
100
+ context 'when keyword is prefixed with "no_"' do
101
+ let(:block) { proc { no_some_test :some, :args } }
102
+
103
+ it 'builds a negated test' do
104
+ expect(some_test_class)
105
+ .to receive(:new).with(env, :some, :args, negated: true)
106
+ dsl.evaluate
107
+ end
108
+ end
99
109
  end
100
110
  end
101
111
  end
@@ -8,19 +8,19 @@ module Producer::Core
8
8
  subject(:condition) { Condition.new(tests) }
9
9
 
10
10
  describe '.evaluate' do
11
- let(:env) { double('env') }
11
+ let(:env) { double 'env' }
12
12
  let(:block) { proc { :some_condition_code } }
13
13
 
14
14
  it 'delegates to DSL.evaluate' do
15
15
  expect(Condition::DSL)
16
16
  .to receive(:evaluate).with(env) do |&b|
17
- expect(b.call).to eq :some_condition_code
17
+ expect(b).to be block
18
18
  end
19
19
  Condition.evaluate(env, &block)
20
20
  end
21
21
 
22
22
  it 'returns the evaluated condition' do
23
- condition = double('condition')
23
+ condition = double 'condition'
24
24
  allow(Condition::DSL).to receive(:evaluate) { condition }
25
25
  expect(Condition.evaluate(env, &block)).to be condition
26
26
  end
@@ -84,8 +84,10 @@ module Producer::Core
84
84
  end
85
85
 
86
86
  describe '#!' do
87
- %w[true false].each do |b|
87
+ [true, false].each do |b|
88
88
  context "when #met? return #{b}" do
89
+ before { allow(condition).to receive(:met?) { b } }
90
+
89
91
  it 'returns the negated #met?' do
90
92
  expect(condition.!).to be !condition.met?
91
93
  end
@@ -9,7 +9,7 @@ module Producer::Core
9
9
  expect(env.instance_eval { @output }).to eq $stdout
10
10
  end
11
11
 
12
- it 'assigns nil as a default target' do
12
+ it 'assigns no default target' do
13
13
  expect(env.target).not_to be
14
14
  end
15
15
  end
@@ -25,11 +25,11 @@ module Producer::Core
25
25
  end
26
26
 
27
27
  describe '#target' do
28
- let(:target) { Object.new }
28
+ let(:target) { double 'target' }
29
29
 
30
30
  it 'returns the defined target' do
31
31
  env.target = target
32
- expect(env.target).to eq target
32
+ expect(env.target).to be target
33
33
  end
34
34
  end
35
35
 
@@ -41,7 +41,7 @@ module Producer::Core
41
41
  end
42
42
 
43
43
  it 'returns the remote' do
44
- remote = double('remote')
44
+ remote = double 'remote'
45
45
  allow(Remote).to receive(:new) { remote }
46
46
  expect(env.remote).to eq remote
47
47
  end
@@ -12,24 +12,22 @@ module Producer::Core
12
12
  end
13
13
 
14
14
  describe '#process_task' do
15
- let(:action) { double('action') }
15
+ let(:action) { double 'action' }
16
16
  let(:task) { double('task', actions: [action]).as_null_object }
17
17
 
18
18
  context 'when task condition is met' do
19
19
  it 'applies the actions' do
20
- expect(action).to receive(:apply)
21
- interpreter.process_task(task)
20
+ expect(action).to receive :apply
21
+ interpreter.process_task task
22
22
  end
23
23
  end
24
24
 
25
25
  context 'when task condition is not met' do
26
- before do
27
- allow(task).to receive(:condition_met?) { false }
28
- end
26
+ before { allow(task).to receive(:condition_met?) { false } }
29
27
 
30
28
  it 'does not apply the actions' do
31
- expect(action).not_to receive(:apply)
32
- interpreter.process_task(task)
29
+ expect(action).not_to receive :apply
30
+ interpreter.process_task task
33
31
  end
34
32
  end
35
33
  end
@@ -4,14 +4,14 @@ module Producer::Core
4
4
  describe Recipe::DSL do
5
5
  include FixturesHelpers
6
6
 
7
- let(:code) { proc { } }
7
+ let(:code) { proc { :some_recipe_code } }
8
8
  let(:env) { double('env').as_null_object }
9
9
  subject(:dsl) { Recipe::DSL.new(&code) }
10
10
 
11
11
  describe '.evaluate' do
12
12
  let(:code) { 'nil' }
13
13
 
14
- it 'builds a new DSL sandbox with given code' do
14
+ it 'builds a new DSL sandbox with given code as string' do
15
15
  expect(Recipe::DSL).to receive(:new).with(code).and_call_original
16
16
  Recipe::DSL.evaluate(code, env)
17
17
  end
@@ -24,7 +24,7 @@ module Producer::Core
24
24
  end
25
25
 
26
26
  it 'builds a recipe with evaluated tasks' do
27
- dsl = Recipe::DSL.new('task(:some_task) { }')
27
+ dsl = Recipe::DSL.new { task(:some_task) { } }
28
28
  allow(Recipe::DSL).to receive(:new) { dsl }
29
29
  expect(Recipe).to receive(:new).with(dsl.tasks)
30
30
  Recipe::DSL.evaluate(code, env)
@@ -62,7 +62,7 @@ module Producer::Core
62
62
  let(:code) { proc { task(:some_task) { } } }
63
63
 
64
64
  it 'returns registered tasks' do
65
- dsl.evaluate(env)
65
+ dsl.evaluate env
66
66
  expect(dsl.tasks[0].name).to eq :some_task
67
67
  end
68
68
  end
@@ -70,11 +70,11 @@ module Producer::Core
70
70
  describe '#evaluate' do
71
71
  it 'evaluates its code' do
72
72
  dsl = Recipe::DSL.new { throw :recipe_code }
73
- expect { dsl.evaluate(env) }.to throw_symbol :recipe_code
73
+ expect { dsl.evaluate env }.to throw_symbol :recipe_code
74
74
  end
75
75
 
76
76
  it 'returns itself' do
77
- expect(dsl.evaluate(env)).to eq dsl
77
+ expect(dsl.evaluate env).to eq dsl
78
78
  end
79
79
  end
80
80
 
@@ -85,8 +85,8 @@ module Producer::Core
85
85
  let(:code) { proc { env.some_message } }
86
86
 
87
87
  it 'returns the current environment' do
88
- expect(env).to receive(:some_message)
89
- dsl.evaluate(env)
88
+ expect(env).to receive :some_message
89
+ dsl.evaluate env
90
90
  end
91
91
  end
92
92
 
@@ -96,7 +96,7 @@ module Producer::Core
96
96
  subject(:dsl) { Recipe::DSL.new(code) }
97
97
 
98
98
  it 'sources the recipe given as argument' do
99
- expect { dsl.evaluate(env) }.to throw_symbol :recipe_code
99
+ expect { dsl.evaluate env }.to throw_symbol :recipe_code
100
100
  end
101
101
  end
102
102
 
@@ -114,8 +114,8 @@ module Producer::Core
114
114
 
115
115
  it 'builds a new evaluated task' do
116
116
  expect(Task)
117
- .to receive(:evaluate).with(:some_task, env) do |&block|
118
- expect(block.call).to eq :some_value
117
+ .to receive(:evaluate).with(:some_task, env) do |&b|
118
+ expect(b.call).to eq :some_value
119
119
  end
120
120
  dsl
121
121
  end
@@ -7,7 +7,7 @@ module Producer::Core
7
7
  subject(:recipe) { Recipe.new }
8
8
 
9
9
  describe '.evaluate_from_file' do
10
- let(:env) { double('env') }
10
+ let(:env) { double 'env' }
11
11
  let(:filepath) { fixture_path_for 'recipes/empty.rb' }
12
12
 
13
13
  it 'delegates to DSL.evaluate with the recipe file content' do
@@ -17,7 +17,7 @@ module Producer::Core
17
17
  end
18
18
 
19
19
  it 'returns the evaluated recipe' do
20
- recipe = double('recipe')
20
+ recipe = double 'recipe'
21
21
  allow(Recipe::DSL).to receive(:evaluate) { recipe }
22
22
  expect(Recipe.evaluate_from_file(filepath, env)).to be recipe
23
23
  end
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  module Producer::Core
4
4
  describe Remote::Environment do
5
5
  let(:variables) { { 'FOO' => 'bar', 'BAZ' => 'qux' } }
6
- subject(:environment) { Remote::Environment.new(variables) }
6
+ let(:string) { "FOO=bar\nBAZ=qux" }
7
+ let(:argument) { variables }
8
+ subject(:environment) { Remote::Environment.new(argument) }
7
9
 
8
10
  describe '#initialize' do
9
11
  context 'when a hash is given' do
@@ -13,7 +15,7 @@ module Producer::Core
13
15
  end
14
16
 
15
17
  context 'when a string is given' do
16
- subject(:environment) { Remote::Environment.new("FOO=bar\nBAZ=qux") }
18
+ let(:argument) { string }
17
19
 
18
20
  it 'assigns the key/value pairs' do
19
21
  expect(environment.instance_eval { @variables }).to eq variables
@@ -15,12 +15,12 @@ module Producer::Core
15
15
  before { sftp_story }
16
16
 
17
17
  it 'builds a new SFTP session' do
18
- expect(remote.session.sftp).to receive(:connect)
18
+ expect(remote.session.sftp).to receive :connect
19
19
  fs.sftp
20
20
  end
21
21
 
22
22
  it 'returns the new SFTP session' do
23
- session = double('session')
23
+ session = double 'session'
24
24
  allow(remote.session.sftp).to receive(:connect) { session }
25
25
  expect(fs.sftp).to be session
26
26
  end
@@ -35,7 +35,7 @@ module Producer::Core
35
35
  # part of net-ssh story helpers, which are more close to integration tests.
36
36
  describe '#has_file?', :ssh do
37
37
  let(:file_path) { "some_file_path" }
38
- let(:stat) { double('stat') }
38
+ let(:stat) { double 'stat' }
39
39
 
40
40
  before do
41
41
  sftp_story
@@ -44,35 +44,31 @@ module Producer::Core
44
44
 
45
45
  context 'when path given as argument exists' do
46
46
  context 'when path is a file' do
47
- before do
48
- allow(stat).to receive(:file?) { true }
49
- end
47
+ before { allow(stat).to receive(:file?) { true } }
50
48
 
51
49
  it 'returns true' do
52
- expect(fs.has_file?(file_path)).to be true
50
+ expect(fs.has_file? file_path).to be true
53
51
  end
54
52
  end
55
53
 
56
54
  context 'when path is not a file' do
57
- before do
58
- allow(stat).to receive(:file?) { false }
59
- end
55
+ before { allow(stat).to receive(:file?) { false } }
60
56
 
61
57
  it 'returns false' do
62
- expect(fs.has_file?(file_path)).to be false
58
+ expect(fs.has_file? file_path).to be false
63
59
  end
64
60
  end
65
61
  end
66
62
 
67
63
  context 'when querying the path raises a Net::SFTP::StatusException' do
68
64
  before do
69
- response = double('response', code: '42', message: 'some message')
65
+ response = double 'response', code: '42', message: 'some message'
70
66
  ex = Net::SFTP::StatusException.new(response)
71
67
  allow(stat).to receive(:file?).and_raise(ex)
72
68
  end
73
69
 
74
70
  it 'returns false' do
75
- expect(fs.has_file?(file_path)).to be false
71
+ expect(fs.has_file? file_path).to be false
76
72
  end
77
73
  end
78
74
  end
@@ -7,7 +7,7 @@ module Producer::Core
7
7
 
8
8
  describe '#hostname' do
9
9
  it 'returns the assignated hostname' do
10
- expect(remote.hostname).to be hostname
10
+ expect(remote.hostname).to eq hostname
11
11
  end
12
12
  end
13
13
 
@@ -69,12 +69,12 @@ module Producer::Core
69
69
 
70
70
  describe '#fs' do
71
71
  it 'builds a new FS' do
72
- expect(Remote::FS).to receive(:new)
72
+ expect(Remote::FS).to receive :new
73
73
  remote.fs
74
74
  end
75
75
 
76
76
  it 'returns the new FS instance' do
77
- fs = double('fs')
77
+ fs = double 'fs'
78
78
  allow(Remote::FS).to receive(:new) { fs }
79
79
  expect(remote.fs).to be fs
80
80
  end
@@ -103,7 +103,7 @@ module Producer::Core
103
103
  ch.sends_exec command
104
104
  ch.gets_data arguments
105
105
  end
106
- expect(remote.execute(command)).to eq arguments
106
+ expect(remote.execute command).to eq arguments
107
107
  end
108
108
 
109
109
  it 'raises an exception when the exit status code is not 0' do
@@ -112,7 +112,7 @@ module Producer::Core
112
112
  ch.gets_data arguments
113
113
  ch.gets_exit_status 1
114
114
  end
115
- expect { remote.execute(command) }
115
+ expect { remote.execute command }
116
116
  .to raise_error(RemoteCommandExecutionError)
117
117
  end
118
118
  end
@@ -134,7 +134,7 @@ module Producer::Core
134
134
  end
135
135
 
136
136
  it 'returns the environment' do
137
- environment = double('environment')
137
+ environment = double 'environment'
138
138
  allow(Remote::Environment).to receive(:new) { environment }
139
139
  expect(remote.environment).to be environment
140
140
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module Producer::Core
4
4
  describe Task::DSL do
5
5
  let(:block) { proc { } }
6
- let(:env) { double('env') }
6
+ let(:env) { double 'env' }
7
7
  subject(:dsl) { Task::DSL.new(&block) }
8
8
 
9
9
  %w[echo sh].each do |action|
@@ -16,7 +16,11 @@ module Producer::Core
16
16
  let(:name) { :some_task }
17
17
 
18
18
  it 'builds a new DSL sandbox with given code' do
19
- expect(Task::DSL).to receive(:new).with(&block).and_call_original
19
+ dsl = double('dsl').as_null_object
20
+ expect(Task::DSL).to receive(:new).with(no_args) do |&b|
21
+ expect(b).to be block
22
+ dsl
23
+ end
20
24
  Task::DSL.evaluate(name, env, &block)
21
25
  end
22
26
 
@@ -38,7 +42,7 @@ module Producer::Core
38
42
  end
39
43
 
40
44
  it 'returns the task' do
41
- task = double('task')
45
+ task = double 'task'
42
46
  allow(Task).to receive(:new) { task }
43
47
  expect(Task::DSL.evaluate(name, env, &block)).to be task
44
48
  end
@@ -57,7 +61,7 @@ module Producer::Core
57
61
  end
58
62
 
59
63
  it 'assigns true as the condition' do
60
- expect(dsl.instance_eval { @condition }).to be_true
64
+ expect(dsl.instance_eval { @condition }).to be true
61
65
  end
62
66
  end
63
67
 
@@ -68,11 +72,20 @@ module Producer::Core
68
72
  end
69
73
  end
70
74
 
75
+ describe '#condition' do
76
+ context 'without block' do
77
+ it 'returns the assigned condition' do
78
+ dsl.instance_eval { @condition = :some_condition }
79
+ expect(dsl.condition).to be :some_condition
80
+ end
81
+ end
82
+ end
83
+
71
84
  describe '#evaluate' do
72
85
  let(:block) { proc { throw :task_code } }
73
86
 
74
87
  it 'evaluates its code' do
75
- expect { dsl.evaluate(env) }
88
+ expect { dsl.evaluate env }
76
89
  .to throw_symbol :task_code
77
90
  end
78
91
 
@@ -82,7 +95,7 @@ module Producer::Core
82
95
 
83
96
  before do
84
97
  Task::DSL.define_action(:some_action, some_action_class)
85
- dsl.evaluate(env)
98
+ dsl.evaluate env
86
99
  end
87
100
 
88
101
  it 'registers the action' do
@@ -118,14 +131,5 @@ module Producer::Core
118
131
  end
119
132
  end
120
133
  end
121
-
122
- describe '#condition' do
123
- context 'without block' do
124
- it 'returns the assigned condition' do
125
- dsl.instance_eval { @condition = :some_condition }
126
- expect(dsl.condition).to be :some_condition
127
- end
128
- end
129
- end
130
134
  end
131
135
  end
@@ -3,24 +3,24 @@ require 'spec_helper'
3
3
  module Producer::Core
4
4
  describe Task do
5
5
  let(:name) { :some_task }
6
- let(:action) { double('action') }
7
- let(:condition) { double('condition') }
6
+ let(:action) { double 'action' }
7
+ let(:condition) { double 'condition' }
8
8
  subject(:task) { Task.new(name, [action], condition) }
9
9
 
10
10
  describe '.evaluate' do
11
- let(:env) { double('env') }
12
- let(:block) { proc { :some_value } }
11
+ let(:env) { double 'env' }
12
+ let(:block) { proc { :some_task_code } }
13
13
 
14
14
  it 'delegates to DSL.evaluate' do
15
15
  expect(Task::DSL)
16
16
  .to receive(:evaluate).with(name, env) do |&b|
17
- expect(b.call).to eq :some_value
17
+ expect(b).to be block
18
18
  end
19
19
  Task.evaluate(name, env, &block)
20
20
  end
21
21
 
22
22
  it 'returns the evaluated task' do
23
- task = double('task')
23
+ task = double 'task'
24
24
  allow(Task::DSL).to receive(:evaluate) { task }
25
25
  expect(Task.evaluate(name, env, &block)).to be task
26
26
  end
@@ -40,14 +40,14 @@ module Producer::Core
40
40
  end
41
41
 
42
42
  context 'when only the name is given as argument' do
43
- subject(:task) { Task.new(name) }
43
+ subject(:task) { Task.new(name) }
44
44
 
45
45
  it 'assigns no action' do
46
46
  expect(task.actions).to be_empty
47
47
  end
48
48
 
49
- it 'assigns a truthy condition' do
50
- expect(task.condition).to be_true
49
+ it 'assigns a true condition' do
50
+ expect(task.condition).to be true
51
51
  end
52
52
  end
53
53
  end
@@ -4,26 +4,79 @@ module Producer::Core
4
4
  describe Test do
5
5
  let(:env) { double 'env' }
6
6
  let(:arguments) { [:some, :arguments] }
7
- subject(:action) { Test.new(env, *arguments) }
7
+ subject(:test) { Test.new(env, *arguments) }
8
8
 
9
9
  describe '#initialize' do
10
10
  it 'assigns the env' do
11
- expect(action.instance_eval { @env }).to be env
11
+ expect(test.instance_eval { @env }).to be env
12
12
  end
13
+
13
14
  it 'assigns the arguments' do
14
- expect(action.instance_eval { @arguments }).to eq arguments
15
+ expect(test.instance_eval { @arguments }).to eq arguments
16
+ end
17
+
18
+ it 'assigns negated as false by default' do
19
+ expect(test.instance_eval { @negated }).to be false
20
+ end
21
+
22
+ context 'when negated option is true' do
23
+ subject(:test) { Test.new(env, *arguments, negated: true) }
24
+
25
+ it 'assigns negated as true' do
26
+ expect(test.instance_eval { @negated }).to be true
27
+ end
15
28
  end
16
29
  end
17
30
 
18
31
  describe '#env' do
19
32
  it 'returns the assigned env' do
20
- expect(action.env).to be env
33
+ expect(test.env).to be env
21
34
  end
22
35
  end
23
36
 
24
37
  describe '#arguments' do
25
38
  it 'returns the assigned arguments' do
26
- expect(action.arguments).to eq arguments
39
+ expect(test.arguments).to eq arguments
40
+ end
41
+ end
42
+
43
+ describe '#negated?' do
44
+ it 'returns false' do
45
+ expect(test.negated?).to be false
46
+ end
47
+
48
+ context 'when test is negated' do
49
+ subject(:test) { Test.new(env, *arguments, negated: true) }
50
+
51
+ it 'returns true' do
52
+ expect(test.negated?).to be true
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#pass?' do
58
+ it 'returns true when #verify is true' do
59
+ allow(test).to receive(:verify) { true }
60
+ expect(test.pass?).to be true
61
+ end
62
+
63
+ it 'returns false when #verify is false' do
64
+ allow(test).to receive(:verify) { false }
65
+ expect(test.pass?).to be false
66
+ end
67
+
68
+ context 'when test is negated' do
69
+ subject(:test) { Test.new(env, *arguments, negated: true) }
70
+
71
+ it 'returns false when #verify is true' do
72
+ allow(test).to receive(:verify) { true }
73
+ expect(test.pass?).to be false
74
+ end
75
+
76
+ it 'returns true when #verify is false' do
77
+ allow(test).to receive(:verify) { false }
78
+ expect(test.pass?).to be true
79
+ end
27
80
  end
28
81
  end
29
82
  end
@@ -10,8 +10,8 @@ module Producer::Core
10
10
  expect(has_env).to be_a Test
11
11
  end
12
12
 
13
- describe '#success?' do
14
- let(:environment) { double('environment') }
13
+ describe '#verify' do
14
+ let(:environment) { double 'environment' }
15
15
 
16
16
  before do
17
17
  allow(env.remote).to receive(:environment) { environment }
@@ -19,22 +19,22 @@ module Producer::Core
19
19
 
20
20
  it 'stringifies the queried variable name' do
21
21
  expect(environment).to receive(:has_key?).with(kind_of(String))
22
- has_env.success?
22
+ has_env.verify
23
23
  end
24
24
 
25
25
  it 'upcases the queried variable name' do
26
26
  expect(environment).to receive(:has_key?).with('SOME_VARIABLE_NAME')
27
- has_env.success?
27
+ has_env.verify
28
28
  end
29
29
 
30
30
  it 'returns true when remote environment var is defined' do
31
31
  allow(environment).to receive(:has_key?) { true }
32
- expect(has_env.success?).to be true
32
+ expect(has_env.verify).to be true
33
33
  end
34
34
 
35
35
  it 'returns false when remote environment var is not defined' do
36
36
  allow(environment).to receive(:has_key?) { false }
37
- expect(has_env.success?).to be false
37
+ expect(has_env.verify).to be false
38
38
  end
39
39
  end
40
40
  end
@@ -10,18 +10,18 @@ module Producer::Core
10
10
  expect(has_file).to be_a Test
11
11
  end
12
12
 
13
- describe '#success?', :ssh do
13
+ describe '#verify', :ssh do
14
14
  before { sftp_story }
15
15
 
16
16
  it 'delegates the call on remote FS' do
17
17
  expect(env.remote.fs).to receive(:has_file?).with(filepath)
18
- has_file.success?
18
+ has_file.verify
19
19
  end
20
20
 
21
21
  it 'returns the file existence' do
22
- existence = double('existence')
22
+ existence = double 'existence'
23
23
  allow(env.remote.fs).to receive(:has_file?) { existence }
24
- expect(has_file.success?).to be existence
24
+ expect(has_file.verify).to be existence
25
25
  end
26
26
  end
27
27
  end
@@ -36,7 +36,7 @@ module NetSSHStoryHelpers
36
36
  def sftp_story
37
37
  story do |session|
38
38
  ch = session.opens_channel
39
- ch.sends_subsystem('sftp')
39
+ ch.sends_subsystem 'sftp'
40
40
  ch.sends_packet(
41
41
  Net::SFTP::Constants::PacketTypes::FXP_INIT, :long,
42
42
  Net::SFTP::Session::HIGHEST_PROTOCOL_VERSION_SUPPORTED
@@ -1,9 +1,9 @@
1
1
  module TestsHelpers
2
2
  def test_ok
3
- double('test', success?: true)
3
+ double 'test', pass?: true
4
4
  end
5
5
 
6
6
  def test_ko
7
- double('test', success?: false)
7
+ double 'test', pass?: false
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
@@ -127,6 +127,7 @@ files:
127
127
  - features/tasks/evaluation.feature
128
128
  - features/tests/has_env.feature
129
129
  - features/tests/has_file.feature
130
+ - features/tests/negated_test.feature
130
131
  - lib/producer/core.rb
131
132
  - lib/producer/core/action.rb
132
133
  - lib/producer/core/actions/echo.rb
@@ -196,7 +197,7 @@ rubyforge_project:
196
197
  rubygems_version: 2.4.5
197
198
  signing_key:
198
199
  specification_version: 4
199
- summary: producer-core-0.1.4
200
+ summary: producer-core-0.1.5
200
201
  test_files:
201
202
  - features/actions/echo.feature
202
203
  - features/actions/sh.feature
@@ -217,6 +218,7 @@ test_files:
217
218
  - features/tasks/evaluation.feature
218
219
  - features/tests/has_env.feature
219
220
  - features/tests/has_file.feature
221
+ - features/tests/negated_test.feature
220
222
  - spec/fixtures/recipes/empty.rb
221
223
  - spec/fixtures/recipes/throw.rb
222
224
  - spec/producer/core/action_spec.rb