ccp 0.2.0 → 0.2.1

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.
@@ -138,8 +138,11 @@ some fixture data for the 'data' object.
138
138
  Ccp can automatically generate fixture data for each commands.
139
139
  Pass :save_fixture option to 'execute' class method to enable it.
140
140
 
141
- * save_fixture : enable write fixture mode if true
142
- * save_fixture_dir : set root dir of fixture (default: tmp/fixtures)
141
+ * fixture_save : set true if you want this feature
142
+ * fixture_dir : set root dir of fixture (default: tmp/fixtures)
143
+ * fixture_kvs : file structure: :file|:dir (default: :file)
144
+ * fixture_ext : file format: :json|:yaml (default: :json)
145
+ * fixture_keys : save data only keys written in here
143
146
 
144
147
  In above example, we can kick it with data[:a] like this.
145
148
 
@@ -147,22 +150,21 @@ In above example, we can kick it with data[:a] like this.
147
150
 
148
151
  And if you want to geneate fixures for this command, just add :save_fixture.
149
152
 
150
- TSFC.execute(:a => 1, :save_fixture => true)
153
+ TSFC.execute(:a => 1, :fixture_save => true)
151
154
 
152
155
  This will create following files.
153
156
 
154
157
  % tree tmp/fixtures
155
158
  tmp/fixtures
156
- └── tsfc
157
- ├── in.yaml
158
- └── out.yaml
159
-
159
+ +- tsfc
160
+ +- read.json
161
+ +- write.json
162
+
160
163
  1 directory, 2 files
161
- % cat tmp/fixtures/tsfc/*
162
- ---
163
- :a: 1
164
- ---
165
- :x: 10
164
+ % cat tmp/fixtures/tsfc/read.json
165
+ {"a":1}
166
+ % cat tmp/fixtures/tsfc/write.json
167
+ {"x":10}
166
168
 
167
169
  === Writing tests
168
170
 
@@ -170,8 +172,8 @@ Use them as stubs and expected data as you like.
170
172
 
171
173
  describe TSFC do
172
174
  it "should work" do
173
- data = YAML.load(Pathname("tmp/fixtures/tsfc/in.yaml").read{})
174
- expected = YAML.load(Pathname("tmp/fixtures/tsfc/out.yaml").read{})
175
+ data = JSON.load(Pathname("tmp/fixtures/tsfc/read.json").read{})
176
+ expected = JSON.load(Pathname("tmp/fixtures/tsfc/write.json").read{})
175
177
 
176
178
  cmd = TSFC.execute(data)
177
179
 
@@ -183,3 +185,61 @@ Use them as stubs and expected data as you like.
183
185
 
184
186
  This code is highly versatile.
185
187
 
188
+ === Filter commands
189
+
190
+ * fixture_save : specify command names (negations can be used as "!")
191
+
192
+ For example, imagine composite commands like this.
193
+
194
+ Program
195
+ +- Cmd1
196
+ +- Cmd2
197
+ +- Cmd3
198
+
199
+ In this case,
200
+
201
+ Program.execute(:fixture_save => true)
202
+
203
+ generates following files.
204
+
205
+ * tmp/fixtures/cmd1/*.json
206
+ * tmp/fixtures/cmd2/*.json
207
+ * tmp/fixtures/cmd3/*.json
208
+ * tmp/fixtures/program/*.json
209
+
210
+ If you want fixture data only for cmd2, run this.
211
+
212
+ Program.execute(:fixture_save => ["Cmd2"])
213
+
214
+ "!" is used for special syntax which means 'negations'.
215
+
216
+ Program.execute(:fixture_save => ["!Program"])
217
+
218
+ will generates fixtures for cmd1,cmd2,cmd3 (in short "not program").
219
+
220
+ === Filter data
221
+
222
+ * fixture_keys : specify data key names (negations can be used as "!")
223
+
224
+ For example, imagine a command like this.
225
+
226
+ class Cmd
227
+ def execute
228
+ data[:x] = 10
229
+ data[:logger].debug "x is set"
230
+ end
231
+ end
232
+
233
+ This code will generate fixtures about 'x' and 'logger' cause it read those vars.
234
+ In many case, we don't need 'logger' object for test data, and furthermore,
235
+ the logger object would be failed in Json serialization.
236
+
237
+ In this case, we want to filter save data. Try fixtures_keys!
238
+
239
+ Cmd.execute(:fixture_save => true, :fixture_keys => ['x'])
240
+
241
+ This will generate "read.json" that contains only 'x'.
242
+ And, "!" can be used for negations as same as "Filter commands".
243
+
244
+ Cmd.execute(:fixture_save => true, :fixture_keys => ['!logger'])
245
+
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency "typed", ">= 0.2.1"
21
+ s.add_dependency "typed", ">= 0.2.2"
22
22
  s.add_dependency "must", ">= 0.2.7"
23
23
  s.add_dependency "dsl_accessor", ">= 0.4.0"
24
24
 
@@ -10,6 +10,9 @@ module Ccp
10
10
  dsl_accessor :comment , true
11
11
  dsl_accessor :logger , proc{ Logger.new($stderr) }
12
12
 
13
+ dsl_accessor :builtin_options, :default => {:profile => profile, :comment => comment, :logger => logger}
14
+ dsl_accessor :default_options, :default => {}
15
+
13
16
  ######################################################################
14
17
  ### Class Methods
15
18
 
@@ -20,17 +23,15 @@ module Ccp
20
23
  return cmd
21
24
  end
22
25
 
23
- def self.default_options
24
- {:profile => profile, :comment => comment, :logger => logger}
25
- end
26
-
27
26
  ######################################################################
28
27
  ### Instance Methods
29
28
 
30
29
  def initialize(options = {})
31
30
  self.receiver = options.delete(:receiver) || self.class.receiver.new
31
+ receiver.parse!(:fixture_keys => self.class.builtin_options.keys.map{|i| "!#{i}"})
32
+ receiver.parse!(options)
33
+ receiver.data.default.merge!(self.class.builtin_options)
32
34
  receiver.data.default.merge!(self.class.default_options)
33
- receiver.data.merge!(options)
34
35
  end
35
36
 
36
37
  def after
@@ -19,8 +19,8 @@ class Ccp::Persistent::Base
19
19
  raise NotImplementedError, "subclass resposibility"
20
20
  end
21
21
 
22
- def save(hash)
23
- hash.keys.each do |key|
22
+ def save(hash, keys = nil)
23
+ (keys || hash.keys).each do |key|
24
24
  self[key] = hash[key]
25
25
  end
26
26
  end
@@ -18,26 +18,30 @@ module Ccp
18
18
  end
19
19
 
20
20
  def execute(cmd)
21
- return super unless fixtures_save?(cmd)
21
+ return super unless fixture_save?(cmd)
22
22
 
23
23
  observer = Ccp::Fixtures::Observer.new(data)
24
24
  observer.start
25
25
  super
26
26
  observer.stop
27
27
 
28
- fixtures_save(cmd, observer.read, observer.write)
28
+ fixture_save(cmd, observer.read, observer.write)
29
29
  end
30
30
 
31
31
  def setup
32
32
  super
33
33
 
34
- self[:fixture_save] = Object # Schema
34
+ # Schema
35
+ self[:fixture_save] = Object # Define schema explicitly to accept true|false|Proc
36
+ self[:fixture_keys] = Object # Define schema explicitly to accept true|[String]
35
37
 
38
+ # Values
36
39
  self[:fixture_dir] = "tmp/fixtures"
37
40
  self[:fixture_kvs] = :file
38
41
  self[:fixture_ext] = :json
39
- self[:fixture_save] = proc{|cmd| false }
40
- self[:fixture_path_for] = proc{|cmd| settings.path(:fixture_dir) + cmd.class.name.underscore}
42
+ self[:fixture_save] = false
43
+ self[:fixture_keys] = true
44
+ self[:fixture_path_for] = default_fixture_path_for
41
45
  end
42
46
 
43
47
  def parse!(options)
@@ -48,28 +52,56 @@ module Ccp
48
52
  super
49
53
  end
50
54
 
51
- def fixtures_save?(cmd)
55
+ def fixture_save?(cmd)
52
56
  case (obj = self[:fixture_save])
53
- when true ; obj
54
- when false; obj
55
- when Proc; obj.call(cmd)
57
+ when true ; true
58
+ when false ; false
59
+ when String; cmd.class.name == obj
60
+ when Array ; ary = obj.map(&:to_s); name = cmd.class.name
61
+ return false if ary.blank?
62
+ return true if ary.include?(name)
63
+ return false if ary.include?("!#{name}")
64
+ return true if ary.size == ary.grep(/^!/).size
65
+ return false
66
+ when Proc ; instance_exec(cmd, &obj).must(true,false) {raise ":fixture_save should return true|false"}
56
67
  else; raise ":fixture_save is invalid: #{obj.class}"
57
68
  end
58
69
  end
59
70
 
60
- def fixtures_save(cmd, read, write)
71
+ def fixture_save(cmd, read, write)
61
72
  path = self[:fixture_path_for].call(cmd)
62
73
  versioned = Ccp::Persistent::Versioned.new(path, :kvs=>self[:fixture_kvs], :ext=>self[:fixture_ext])
63
- versioned["read" ].save(read)
64
- versioned["write"].save(write)
74
+ versioned["read" ].save(read , fixture_keys_filter(read.keys))
75
+ versioned["write"].save(write, fixture_keys_filter(write.keys))
65
76
  end
66
77
 
67
- def fixtures_for(cmd, key)
78
+ def fixture_keys_filter(keys)
79
+ case (obj = self[:fixture_keys])
80
+ when true ; keys
81
+ when false; []
82
+ when Array
83
+ ary = obj.map(&:to_s)
84
+ return keys if ary == []
85
+ if ary.size == ary.grep(/^!/).size
86
+ return keys.dup.reject{|v| ary.include?("!#{v}")}
87
+ else
88
+ ary & keys
89
+ end
90
+ else
91
+ raise ":fixture_keys is invalid: #{obj.class}"
92
+ end
93
+ end
94
+
95
+ def fixture_for(cmd, key)
68
96
  kvs = Ccp::Persistent.lookup(self[:fixture_kvs])
69
97
  code = Ccp::Serializers.lookup(self[:fixture_ext])
70
- path = self[:fixture_path_for].call(cmd) + "#{key}.#{code.ext}.#{kvs.ext}"
98
+ path = instance_exec(cmd, &self[:fixture_path_for]) + "#{key}.#{code.ext}.#{kvs.ext}"
71
99
  return Storage.new(kvs.new(path, code))
72
100
  end
101
+
102
+ def default_fixture_path_for
103
+ proc{|cmd| settings.path(:fixture_dir) + cmd.class.name.underscore}
104
+ end
73
105
  end
74
106
  end
75
107
  end
@@ -1,3 +1,3 @@
1
1
  module Ccp
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+ require 'fileutils'
3
+
4
+ describe Ccp::Invokers::Base do
5
+ def load(path)
6
+ case path.extname
7
+ when ".json"; JSON.load(Pathname(path).read{})
8
+ when ".yaml"; YAML.load(Pathname(path).read{})
9
+ else; raise "load doesn't support #{path.extname}"
10
+ end
11
+ end
12
+
13
+ describe ".execute" do
14
+ before do
15
+ FileUtils.rm_rf("tmp")
16
+ end
17
+
18
+ context "(:fixture_save=>true)" do
19
+ it "should generate read/write fixtures in tmp/fixtures as json files" do
20
+ path = Pathname("tmp/fixtures")
21
+ data = {:breadcrumbs => []}
22
+ opts = {:fixture_save=>true}
23
+
24
+ CompositeInvoker.execute(data.merge(opts))
25
+
26
+ (read = path + "composite_invoker/read.json" ).should exist
27
+ load(read)["breadcrumbs"].should ==
28
+ ["CompositeInvoker#before",
29
+ "Cmd1#before", "Cmd1#execute", "Cmd1#after",
30
+ "Cmd23#before",
31
+ "Cmd23#execute:start",
32
+ "Cmd2#before", "Cmd2#execute", "Cmd2#after",
33
+ "Cmd3#before", "Cmd3#execute", "Cmd3#after",
34
+ "Cmd23#execute:end",
35
+ "Cmd23#after",
36
+ "Cmd4#before", "Cmd4#execute", "Cmd4#after",
37
+ "CompositeInvoker#after"]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -97,3 +97,12 @@ class CompositeInvoker < Ccp::Invokers::Base
97
97
  super
98
98
  end
99
99
  end
100
+
101
+ class TSFC # TestSaveFixtureCmd
102
+ include Ccp::Commands::Core
103
+
104
+ def execute
105
+ data[:a] # read
106
+ data[:x] = 10 # write
107
+ end
108
+ end
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+ require 'fileutils'
3
+
4
+ describe "Ccp::Commands::Core" do
5
+ describe ".execute" do
6
+ before do
7
+ FileUtils.rm_rf("tmp")
8
+ end
9
+
10
+ context "(:fixture_save=>true)" do
11
+ it "should generate read/write fixtures in tmp/fixtures as json files" do
12
+ path = Pathname("tmp/fixtures")
13
+ data = {:a=>"a", :b=>"b", :x=>1, :y=>2}
14
+ opts = {:fixture_save=>true}
15
+
16
+ TSFC.execute(data.merge(opts))
17
+
18
+ load_fixture(path + "tsfc/read.json" ).should == {"a" => "a"}
19
+ load_fixture(path + "tsfc/write.json").should == {"x" => 10}
20
+ end
21
+ end
22
+
23
+ context "(:fixture_save=>true, :fixture_ext=>:yaml)" do
24
+ it "should generate read/write fixtures in tmp/fixtures as yaml files" do
25
+ path = Pathname("tmp/fixtures")
26
+ data = {:a=>"a", :b=>"b", :x=>1, :y=>2}
27
+ opts = {:fixture_save=>true, :fixture_ext=>:yaml}
28
+
29
+ TSFC.execute(data.merge(opts))
30
+
31
+ load_fixture(path + "tsfc/read.yaml" ).should == {"a" => "a"}
32
+ load_fixture(path + "tsfc/write.yaml").should == {"x" => 10}
33
+ end
34
+ end
35
+
36
+ context "(:fixture_save=>true, :fixture_kvs=>:dir)" do
37
+ it "should generate json files in read/write dir" do
38
+ path = Pathname("tmp/fixtures")
39
+ data = {:a=>"a", :b=>"b", :x=>1, :y=>2}
40
+ opts = {:fixture_save=>true, :fixture_kvs=>:dir}
41
+
42
+ TSFC.execute(data.merge(opts))
43
+
44
+ load_fixture(path + "tsfc/read.json/a.json" ).should == "a"
45
+ load_fixture(path + "tsfc/write.json/x.json").should == 10
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+ require 'fileutils'
3
+
4
+ describe Ccp::Invokers::Base do
5
+ before do
6
+ FileUtils.rm_rf("tmp")
7
+ end
8
+
9
+ class ULI < Ccp::Invokers::Base # UsingLoggerInvoker
10
+ def execute
11
+ data[:a]
12
+ data[:logger]
13
+
14
+ data[:x] = 10
15
+ data[:logger] = Logger.new("/dev/null")
16
+ end
17
+ end
18
+
19
+ describe ".execute" do
20
+ context "(:fixture_save=>true)" do
21
+ it "should ignore :logger in default" do
22
+ ULI.execute(:a=>"a", :fixture_save=>true)
23
+
24
+ load_fixture("tmp/fixtures/uli/read.json" ).should == {"a" => "a"}
25
+ load_fixture("tmp/fixtures/uli/write.json" ).should == {"x" => 10}
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,84 @@
1
+ require "spec_helper"
2
+ require 'fileutils'
3
+
4
+ ######################################################################
5
+ ### What means targets
6
+
7
+ describe Cmd1 do
8
+ describe ".execute" do
9
+ FIXTURE_PATH = Pathname("tmp/fixtures/cmd1")
10
+
11
+ before do
12
+ FileUtils.rm_rf(FIXTURE_PATH.to_s)
13
+ end
14
+
15
+ def created_keys
16
+ load_fixture(FIXTURE_PATH + "read.json").keys.sort
17
+ rescue Errno::ENOENT
18
+ []
19
+ end
20
+
21
+ def self.execute(opts = {}, &block)
22
+ context "(#{opts.inspect})" do
23
+ expected = block.call
24
+ it "should create #{expected.inspect}" do
25
+ Cmd1.execute({:breadcrumbs=>[]}.merge(opts))
26
+ created_keys.should == expected
27
+ end
28
+ end
29
+ end
30
+
31
+ ######################################################################
32
+ ### fixture_save
33
+
34
+ # nop when :save is not given
35
+ execute() do
36
+ []
37
+ end
38
+
39
+ execute(:fixture_save => true) do
40
+ ["breadcrumbs"]
41
+ end
42
+
43
+ ######################################################################
44
+ ### accepts
45
+
46
+ execute(:fixture_save => true, :fixture_keys => true) do
47
+ ["breadcrumbs"]
48
+ end
49
+
50
+ execute(:fixture_save => true, :fixture_keys => ['x']) do
51
+ []
52
+ end
53
+
54
+ ######################################################################
55
+ ### excepts
56
+
57
+ execute(:fixture_save => true, :fixture_keys => ['!breadcrumbs']) do
58
+ []
59
+ end
60
+
61
+ execute(:fixture_save => true, :fixture_keys => ['!breadcrumbsXXX']) do
62
+ ["breadcrumbs"]
63
+ end
64
+
65
+ ######################################################################
66
+ ### accepts & excepts
67
+
68
+ execute(:fixture_save => true, :fixture_keys => ['xxx', '!breadcrumbs']) do
69
+ []
70
+ end
71
+
72
+ execute(:fixture_save => true, :fixture_keys => ['xxx', '!xxx']) do
73
+ []
74
+ end
75
+
76
+ execute(:fixture_save => true, :fixture_keys => ['breadcrumbs', '!xxx']) do
77
+ ["breadcrumbs"]
78
+ end
79
+
80
+ execute(:fixture_save => true, :fixture_keys => ['breadcrumbs', '!breadcrumbs']) do
81
+ ["breadcrumbs"]
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+ require 'fileutils'
3
+
4
+ describe "Ccp::Commands::Core" do
5
+ describe ".execute" do
6
+ before do
7
+ FileUtils.rm_rf("tmp")
8
+ end
9
+
10
+ context "(:fixture_save=>true, :fixture_dir=>...)" do
11
+ it "should generate read/write fixtures in <save_fixture_dir> as json files" do
12
+ path = Pathname("tmp/test/fixtures")
13
+ data = {:a=>"a", :b=>"b", :x=>1, :y=>2}
14
+ opts = {:fixture_save=>true, :fixture_dir=>path.to_s}
15
+
16
+ TSFC.execute(data.merge(opts))
17
+
18
+ load_fixture(path + "tsfc/read.json" ).should == {"a" => "a"}
19
+ load_fixture(path + "tsfc/write.json").should == {"x" => 10}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,92 @@
1
+ require "spec_helper"
2
+ require 'fileutils'
3
+
4
+ ######################################################################
5
+ ### Why means ACL
6
+
7
+ describe Ccp::Commands::Composite do
8
+ describe ".execute" do
9
+ FIXTURE_ROOT = "tmp/fixtures"
10
+
11
+ before do
12
+ FileUtils.rm_rf(FIXTURE_ROOT.to_s)
13
+ end
14
+
15
+ def created_fixtures
16
+ Dir.chdir(FIXTURE_ROOT){Dir["*/read.json"].map{|i| File.dirname(i)}.sort}
17
+ rescue Errno::ENOENT
18
+ []
19
+ end
20
+
21
+ def self.execute(opts = {}, &block)
22
+ context "(#{opts.inspect})" do
23
+ expected = block.call
24
+ it "should create #{expected.inspect}" do
25
+ Program.execute({:breadcrumbs=>[]}.merge(opts))
26
+ created_fixtures.should == expected
27
+ end
28
+ end
29
+ end
30
+
31
+ ######################################################################
32
+ ### fixture_save
33
+
34
+ # nop when :save is not given
35
+ execute() do
36
+ []
37
+ end
38
+
39
+ # nop when :save is false
40
+ execute(:fixture_save => false) do
41
+ []
42
+ end
43
+
44
+ execute(:fixture_save => true) do
45
+ ["cmd1", "cmd2", "cmd3", "program"]
46
+ end
47
+
48
+ ######################################################################
49
+ ### accepts
50
+
51
+ execute(:fixture_save => 'Cmd2') do
52
+ ["cmd2"]
53
+ end
54
+
55
+ execute(:fixture_save => ['Cmd2']) do
56
+ ["cmd2"]
57
+ end
58
+
59
+ execute(:fixture_save => ['Cmd2', 'Cmd3']) do
60
+ ["cmd2", "cmd3"]
61
+ end
62
+
63
+ # no match
64
+ execute(:fixture_save => ['CmdX']) do
65
+ []
66
+ end
67
+
68
+ ######################################################################
69
+ ### excepts
70
+
71
+ execute(:fixture_save => ['!Cmd1']) do
72
+ ["cmd2", "cmd3", "program"]
73
+ end
74
+
75
+ execute(:fixture_save => ['!Cmd2', '!Program']) do
76
+ ["cmd1", "cmd3"]
77
+ end
78
+
79
+ ######################################################################
80
+ ### accepts & excepts
81
+
82
+ # :accept has a higher priority
83
+ execute(:fixture_save => ['Cmd1','!Cmd2']) do
84
+ ['cmd1']
85
+ end
86
+
87
+ # :accept is used even if settings are conflicted
88
+ execute(:fixture_save => ['Cmd1','!Cmd1']) do
89
+ ['cmd1']
90
+ end
91
+ end
92
+ end
@@ -12,3 +12,11 @@ def breadcrumbs_receiver
12
12
  return r
13
13
  end
14
14
 
15
+ def load_fixture(path)
16
+ path = Pathname(path)
17
+ case path.extname
18
+ when ".json"; JSON.load(Pathname(path).read{})
19
+ when ".yaml"; YAML.load(Pathname(path).read{})
20
+ else; raise "load doesn't support #{path.extname}"
21
+ end
22
+ 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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - maiha
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-02 00:00:00 +09:00
18
+ date: 2012-05-07 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 21
29
+ hash: 19
30
30
  segments:
31
31
  - 0
32
32
  - 2
33
- - 1
34
- version: 0.2.1
33
+ - 2
34
+ version: 0.2.2
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -140,13 +140,18 @@ files:
140
140
  - spec/commands/core_spec.rb
141
141
  - spec/commands/executable_spec.rb
142
142
  - spec/invokers/base_spec.rb
143
+ - spec/invokers/save_fixture_spec.rb
143
144
  - spec/models.rb
144
145
  - spec/persistent/base_spec.rb
145
146
  - spec/persistent/dir_spec.rb
146
147
  - spec/persistent/file_spec.rb
147
148
  - spec/persistent/tsv_spec.rb
148
149
  - spec/persistent/versioned_spec.rb
149
- - spec/receivers/fixture_save_spec.rb
150
+ - spec/receivers/fixture_save_how_spec.rb
151
+ - spec/receivers/fixture_save_ignore_logger_spec.rb
152
+ - spec/receivers/fixture_save_what_spec.rb
153
+ - spec/receivers/fixture_save_where_spec.rb
154
+ - spec/receivers/fixture_save_why_spec.rb
150
155
  - spec/serializers/core_spec.rb
151
156
  - spec/serializers/json_spec.rb
152
157
  - spec/serializers/spec.rb
@@ -1,79 +0,0 @@
1
- require "spec_helper"
2
- require 'fileutils'
3
-
4
- describe Ccp::Receivers::Fixtures do
5
- class TSFC # TestSaveFixtureCmd
6
- include Ccp::Commands::Core
7
-
8
- def execute
9
- data[:a] # read
10
- data[:x] = 10 # write
11
- end
12
- end
13
-
14
- def load(path)
15
- case path.extname
16
- when ".json"; JSON.load(Pathname(path).read{})
17
- when ".yaml"; YAML.load(Pathname(path).read{})
18
- else; raise "load doesn't support #{path.extname}"
19
- end
20
- end
21
-
22
- describe ".execute" do
23
- before do
24
- FileUtils.rm_rf("tmp")
25
- end
26
-
27
- context "(:fixture_save=>true)" do
28
- it "should generate read/write fixtures in tmp/fixtures as json files" do
29
- path = Pathname("tmp/fixtures")
30
- data = {:a=>"a", :b=>"b", :x=>1, :y=>2}
31
- opts = {:fixture_save=>true}
32
-
33
- TSFC.execute(data.merge(opts))
34
-
35
- load(path + "tsfc/read.json" ).should == {"a" => "a"}
36
- load(path + "tsfc/write.json").should == {"x" => 10}
37
- end
38
- end
39
-
40
- context "(:fixture_save=>true, :fixture_ext=>:yaml)" do
41
- it "should generate read/write fixtures in tmp/fixtures as yaml files" do
42
- path = Pathname("tmp/fixtures")
43
- data = {:a=>"a", :b=>"b", :x=>1, :y=>2}
44
- opts = {:fixture_save=>true, :fixture_ext=>:yaml}
45
-
46
- TSFC.execute(data.merge(opts))
47
-
48
- load(path + "tsfc/read.yaml" ).should == {"a" => "a"}
49
- load(path + "tsfc/write.yaml").should == {"x" => 10}
50
- end
51
- end
52
-
53
- context "(:fixture_save=>true, :fixture_dir=>...)" do
54
- it "should generate read/write fixtures in <save_fixture_dir> as json files" do
55
- path = Pathname("tmp/test/fixtures")
56
- data = {:a=>"a", :b=>"b", :x=>1, :y=>2}
57
- opts = {:fixture_save=>true, :fixture_dir=>path.to_s}
58
-
59
- TSFC.execute(data.merge(opts))
60
-
61
- load(path + "tsfc/read.json" ).should == {"a" => "a"}
62
- load(path + "tsfc/write.json").should == {"x" => 10}
63
- end
64
- end
65
-
66
- context "(:fixture_save=>true, :fixture_kvs=>:dir)" do
67
- it "should generate json files in read/write dir" do
68
- path = Pathname("tmp/fixtures")
69
- data = {:a=>"a", :b=>"b", :x=>1, :y=>2}
70
- opts = {:fixture_save=>true, :fixture_kvs=>:dir}
71
-
72
- TSFC.execute(data.merge(opts))
73
-
74
- load(path + "tsfc/read.json/a.json" ).should == "a"
75
- load(path + "tsfc/write.json/x.json").should == 10
76
- end
77
- end
78
- end
79
- end