ccp 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ tmp/*
@@ -116,6 +116,24 @@ This profile option prints benchmarks of commands.
116
116
  ...
117
117
 
118
118
 
119
+ == Skip commands
120
+
121
+ "skip" prefixed data key names are reserved for command skipping feature.
122
+ When data[:skip_XXX] given, the XXX command won't be invoked.
123
+
124
+ class Program
125
+ include Ccp::Commands::Composite
126
+ command Cmd1
127
+ command Cmd2
128
+ end
129
+
130
+ # normal case
131
+ Program.execute # => Both Cmd1 and Cmd2 will be called
132
+
133
+ # with skip
134
+ Program.execute(:skip_cmd1 => true) # => Both Cmd2 will be called
135
+
136
+
119
137
  == Fixtures
120
138
 
121
139
  Let's imagine a following command that just read :a and write :x.
@@ -7,6 +7,7 @@ module Ccp
7
7
  autoload :Variables , 'ccp/receivers/variables'
8
8
  autoload :Executable , 'ccp/receivers/executable'
9
9
  autoload :Aroundable , 'ccp/receivers/aroundable'
10
+ autoload :Skippable , 'ccp/receivers/skippable'
10
11
  autoload :Commentable , 'ccp/receivers/commentable'
11
12
  autoload :Profileable , 'ccp/receivers/profileable'
12
13
  autoload :Fixtures , 'ccp/receivers/fixtures'
@@ -10,6 +10,7 @@ module Ccp
10
10
  include Executable
11
11
  include Profileable
12
12
  include Aroundable
13
+ include Skippable
13
14
  include Fixtures
14
15
 
15
16
  # ensure to call '#setup' for module initializations
@@ -84,13 +84,7 @@ module Ccp
84
84
  end
85
85
 
86
86
  def default_fixture_fail(cmd, key, exp, got)
87
- if exp == nil and got == nil
88
- raise Failed, "#{cmd.class} should write #{key} but not found"
89
- end
90
-
91
- exp_info = "%s(%s)" % [exp.inspect.truncate(200), Must::StructInfo.new(exp).compact.inspect]
92
- got_info = "%s(%s)" % [got.inspect.truncate(200), Must::StructInfo.new(got).compact.inspect]
93
- raise Failed, "%s should create %s for %s, but got %s" % [cmd.class, exp_info, key, got_info]
87
+ Ccp::Utils::TestFailed::PROC.call(cmd, key, exp, got)
94
88
  end
95
89
 
96
90
  def fixture_save?(cmd)
@@ -0,0 +1,16 @@
1
+ module Ccp
2
+ module Receivers
3
+ module Skippable
4
+ def execute(cmd)
5
+ return false if skip?(cmd)
6
+ super
7
+ end
8
+
9
+ private
10
+ def skip?(cmd)
11
+ key = "skip_%s" % cmd.class.name.underscore.gsub("/","_")
12
+ data.set?(key)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -3,5 +3,6 @@ module Ccp
3
3
  autoload :Data , 'ccp/utils/data'
4
4
  autoload :Colorize , 'ccp/utils/colorize'
5
5
  autoload :Options , 'ccp/utils/options'
6
+ autoload :TestFailed , 'ccp/utils/test_failed'
6
7
  end
7
8
  end
@@ -0,0 +1,46 @@
1
+ module Ccp
2
+ module Utils
3
+ module TestFailed
4
+ Differ = Struct.new(:a, :b, :path)
5
+ class Differ
6
+ def execute
7
+ unless a.class == b.class
8
+ failed("%s expected [%s], but got [%s]" % [path, a.class, b.class])
9
+ end
10
+
11
+ if a.class == Array
12
+ max = [a.size, b.size].max
13
+ (0...max).each do |i|
14
+ Differ.new(a[i], b[i], "#{path}[#{i}]").execute
15
+ end
16
+ return true
17
+ end
18
+
19
+ if a.class == Hash
20
+ (a.keys | b.keys).each do |key|
21
+ Differ.new(a[key], b[key], "#{path}[#{key}]").execute
22
+ end
23
+ return true
24
+ end
25
+
26
+ unless a == b
27
+ failed("%s expected %s, but got %s" % [path, a.inspect, b.inspect])
28
+ end
29
+ end
30
+
31
+ private
32
+ def failed(msg)
33
+ raise Ccp::Failed, msg
34
+ end
35
+ end
36
+
37
+ PROC = proc {|cmd, key, exp, got|
38
+ if exp == nil and got == nil
39
+ raise Ccp::Failed, "#{cmd.class} should write #{key} but not found"
40
+ end
41
+ TestFailed::Differ.new(exp, got, key).execute
42
+ raise Ccp::Failed, "[FATAL] %s expected %s, but got %s" % [cmd.class, exp_type.inspect, got_type.inspect]
43
+ }
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module Ccp
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
@@ -39,7 +39,7 @@ describe Ccp::Receivers::Fixtures do
39
39
  it "should raise when current data doesn't match the given data" do
40
40
  lambda {
41
41
  Cmd1StubInvalidMock.execute
42
- }.should raise_error(/should create/)
42
+ }.should raise_error(/breadcrumbs.*expected.*got.*String/)
43
43
  end
44
44
  end
45
45
 
@@ -0,0 +1,83 @@
1
+ require "spec_helper"
2
+
3
+ describe Ccp::Receivers::Skippable do
4
+ let(:options) { {:breadcrumbs => []} }
5
+ let(:program) { Program }
6
+ let(:data) { program.execute(options).data }
7
+
8
+ def breadcrumbs
9
+ data[:breadcrumbs]
10
+ end
11
+
12
+ describe "#execute" do
13
+ context "(standard case)" do
14
+ it "should execute normally" do
15
+ breadcrumbs.should == ["Program#before", "Cmd1#before", "Cmd1#execute", "Cmd1#after", "Cmd2#before", "Cmd2#execute", "Cmd2#after", "Cmd3#before", "Cmd3#execute", "Cmd3#after", "Program#after"]
16
+ end
17
+ end
18
+
19
+ context "(:skip_cmd1 given)" do
20
+ before { options[:skip_cmd1] = true }
21
+ it "should execute without Cmd1" do
22
+ breadcrumbs.should == ["Program#before", "Cmd2#before", "Cmd2#execute", "Cmd2#after", "Cmd3#before", "Cmd3#execute", "Cmd3#after", "Program#after"]
23
+ end
24
+ end
25
+
26
+ context "(:skip_cmd1, :skip_cmd3 given)" do
27
+ before { options[:skip_cmd1] = true; options[:skip_cmd3] = true }
28
+ it "should execute without Cmd1 and Cmd3" do
29
+ breadcrumbs.should == ["Program#before", "Cmd2#before", "Cmd2#execute", "Cmd2#after", "Program#after"]
30
+ end
31
+ end
32
+
33
+ context "(:skip_program(top level cmd) given)" do
34
+ before { options[:skip_program] = true }
35
+ it "should execute nothing" do
36
+ breadcrumbs.should == []
37
+ end
38
+ end
39
+
40
+ context "(non-matched skip key given)" do
41
+ before { options[:skip_XXX] = true }
42
+ it "should execute normally" do
43
+ breadcrumbs.should == ["Program#before", "Cmd1#before", "Cmd1#execute", "Cmd1#after", "Cmd2#before", "Cmd2#execute", "Cmd2#after", "Cmd3#before", "Cmd3#execute", "Cmd3#after", "Program#after"]
44
+ end
45
+ end
46
+ end
47
+
48
+ context "[moduled cmd]" do
49
+ let(:program) { ::SkippableTest::Program }
50
+
51
+ module ::SkippableTest
52
+ class CmdX < Cmd1
53
+ include Breadcrumbing
54
+ end
55
+
56
+ class Program
57
+ include Ccp::Commands::Composite
58
+ command CmdX
59
+ command Cmd1
60
+ end
61
+ end
62
+
63
+ context "(standard case)" do
64
+ it "should execute normally" do
65
+ breadcrumbs.should == ["SkippableTest::CmdX#before", "SkippableTest::CmdX#execute", "SkippableTest::CmdX#after", "Cmd1#before", "Cmd1#execute", "Cmd1#after"]
66
+ end
67
+ end
68
+
69
+ context "(:skip_cmd1 given)" do
70
+ before { options[:skip_cmd1] = true }
71
+ it "should execute without Cmd1" do
72
+ breadcrumbs.should == ["SkippableTest::CmdX#before", "SkippableTest::CmdX#execute", "SkippableTest::CmdX#after"]
73
+ end
74
+ end
75
+
76
+ context "(:skip_skippable_test_cmd_x given)" do
77
+ before { options[:skip_skippable_test_cmd_x] = true }
78
+ it "should execute without Skippable::CmdX" do
79
+ breadcrumbs.should == ["Cmd1#before", "Cmd1#execute", "Cmd1#after"]
80
+ end
81
+ end
82
+ end
83
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 7
10
- version: 0.2.7
9
+ - 8
10
+ version: 0.2.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - maiha
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-22 00:00:00 +09:00
19
- default_executable:
18
+ date: 2013-02-21 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: typed
@@ -130,6 +129,7 @@ files:
130
129
  - lib/ccp/receivers/none.rb
131
130
  - lib/ccp/receivers/profileable.rb
132
131
  - lib/ccp/receivers/settings.rb
132
+ - lib/ccp/receivers/skippable.rb
133
133
  - lib/ccp/receivers/variables.rb
134
134
  - lib/ccp/serializers.rb
135
135
  - lib/ccp/serializers/core.rb
@@ -139,6 +139,7 @@ files:
139
139
  - lib/ccp/utils/colorize.rb
140
140
  - lib/ccp/utils/fixture_options.rb
141
141
  - lib/ccp/utils/options.rb
142
+ - lib/ccp/utils/test_failed.rb
142
143
  - lib/ccp/version.rb
143
144
  - spec/commands/base_spec.rb
144
145
  - spec/commands/composite_spec.rb
@@ -167,12 +168,12 @@ files:
167
168
  - spec/receivers/fixture_save_where_spec.rb
168
169
  - spec/receivers/fixture_save_why_spec.rb
169
170
  - spec/receivers/fixture_stub_spec.rb
171
+ - spec/receivers/skippable_spec.rb
170
172
  - spec/serializers/core_spec.rb
171
173
  - spec/serializers/json_spec.rb
172
174
  - spec/serializers/spec.rb
173
175
  - spec/serializers/yaml_spec.rb
174
176
  - spec/spec_helper.rb
175
- has_rdoc: true
176
177
  homepage: http://github.com/maiha/ccp
177
178
  licenses: []
178
179
 
@@ -202,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
203
  requirements: []
203
204
 
204
205
  rubyforge_project: ccp
205
- rubygems_version: 1.3.7
206
+ rubygems_version: 1.8.15
206
207
  signing_key:
207
208
  specification_version: 3
208
209
  summary: A Ruby library for Composite Command Programming