ccp 0.1.7 → 0.2.0
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.
- data/ccp.gemspec +1 -1
- data/lib/ccp.rb +4 -2
- data/lib/ccp/invokers/base.rb +2 -2
- data/lib/ccp/persistent.rb +23 -0
- data/lib/ccp/persistent/base.rb +51 -0
- data/lib/ccp/persistent/dir.rb +48 -0
- data/lib/ccp/persistent/file.rb +59 -0
- data/lib/ccp/persistent/tsv.rb +76 -0
- data/lib/ccp/persistent/versioned.rb +90 -0
- data/lib/ccp/receivers.rb +4 -1
- data/lib/ccp/receivers/base.rb +6 -7
- data/lib/ccp/receivers/commentable.rb +1 -1
- data/lib/ccp/receivers/core.rb +14 -0
- data/lib/ccp/receivers/fixtures.rb +75 -0
- data/lib/ccp/receivers/profileable.rb +1 -1
- data/lib/ccp/receivers/settings.rb +21 -0
- data/lib/ccp/receivers/variables.rb +21 -0
- data/lib/ccp/serializers.rb +19 -0
- data/lib/ccp/serializers/core.rb +13 -0
- data/lib/ccp/serializers/json.rb +15 -0
- data/lib/ccp/serializers/yaml.rb +15 -0
- data/lib/ccp/utils.rb +6 -0
- data/lib/ccp/utils/colorize.rb +15 -0
- data/lib/ccp/version.rb +1 -1
- data/spec/{commands_base_spec.rb → commands/base_spec.rb} +0 -0
- data/spec/{commands_composite_spec.rb → commands/composite_spec.rb} +0 -0
- data/spec/{commands_core_spec.rb → commands/core_spec.rb} +0 -0
- data/spec/{commands_executable_spec.rb → commands/executable_spec.rb} +0 -0
- data/spec/{invokers_spec.rb → invokers/base_spec.rb} +0 -0
- data/spec/persistent/base_spec.rb +49 -0
- data/spec/persistent/dir_spec.rb +111 -0
- data/spec/persistent/file_spec.rb +124 -0
- data/spec/persistent/tsv_spec.rb +19 -0
- data/spec/persistent/versioned_spec.rb +110 -0
- data/spec/receivers/fixture_save_spec.rb +79 -0
- data/spec/serializers/core_spec.rb +19 -0
- data/spec/serializers/json_spec.rb +27 -0
- data/spec/serializers/spec.rb +39 -0
- data/spec/serializers/yaml_spec.rb +27 -0
- metadata +39 -18
- data/lib/ccp/colorize.rb +0 -13
- data/lib/ccp/data.rb +0 -37
- data/lib/ccp/receivers/save_fixture.rb +0 -45
- data/spec/data_spec.rb +0 -18
- data/spec/save_fixture_spec.rb +0 -47
data/lib/ccp/data.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'pathname'
|
4
|
-
|
5
|
-
module Ccp
|
6
|
-
module Data
|
7
|
-
module Ext
|
8
|
-
def path(key)
|
9
|
-
self[key].must.coerced(Pathname, String=>proc{|i| Pathname(i)})
|
10
|
-
end
|
11
|
-
|
12
|
-
def merge(options)
|
13
|
-
options.each_pair do |key,val|
|
14
|
-
self[key] = val
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def merge_default(options)
|
19
|
-
options.each_pair do |key,val|
|
20
|
-
default[key] = val
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def data
|
26
|
-
@data ||= Typed::Hash.new.extend Ext
|
27
|
-
end
|
28
|
-
|
29
|
-
def data?(key)
|
30
|
-
data.set?(key)
|
31
|
-
end
|
32
|
-
|
33
|
-
def parse!(options)
|
34
|
-
data.merge(options)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Ccp
|
2
|
-
module Receivers
|
3
|
-
module SaveFixture
|
4
|
-
attr_accessor :save_fixture_dir
|
5
|
-
|
6
|
-
def execute(cmd)
|
7
|
-
if save_fixture?(cmd)
|
8
|
-
observer = Ccp::Fixtures::Observer.new(data)
|
9
|
-
observer.start
|
10
|
-
super
|
11
|
-
observer.stop
|
12
|
-
path = save_fixture_path_for(cmd)
|
13
|
-
Ccp::Fixtures::Writers::YamlWriter[path + "in.yaml" ] = observer.read
|
14
|
-
Ccp::Fixtures::Writers::YamlWriter[path + "out.yaml"] = observer.write
|
15
|
-
else
|
16
|
-
super
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def parse!(options)
|
21
|
-
dir = options.delete(:save_fixture_dir)
|
22
|
-
@save_fixture_dir = dir if dir
|
23
|
-
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
|
-
def save_fixture?(cmd)
|
28
|
-
if data?(:save_fixture)
|
29
|
-
return true
|
30
|
-
else
|
31
|
-
# indivisual fixture is not supported yet
|
32
|
-
return false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def save_fixture_path_for(cmd)
|
37
|
-
Pathname(save_fixture_dir || save_fixture_default_dir) + cmd.class.name.underscore
|
38
|
-
end
|
39
|
-
|
40
|
-
def save_fixture_default_dir
|
41
|
-
"tmp/fixtures"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/spec/data_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Ccp::Data do
|
4
|
-
subject { Object.new.extend Ccp::Data }
|
5
|
-
def data; subject.data; end
|
6
|
-
|
7
|
-
######################################################################
|
8
|
-
### Utils
|
9
|
-
|
10
|
-
describe "#path" do
|
11
|
-
it "should return pathname" do
|
12
|
-
data[:foo] = __FILE__
|
13
|
-
data.path(:foo).should be_kind_of(Pathname)
|
14
|
-
data.path(:foo).basename.should == Pathname("data_spec.rb")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
data/spec/save_fixture_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Ccp::Commands::Base do
|
4
|
-
describe ".execute(:save_fixture=>true)" 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_yaml(path)
|
15
|
-
YAML.load(Pathname(path).read{})
|
16
|
-
end
|
17
|
-
|
18
|
-
def truncate(path)
|
19
|
-
require 'fileutils'
|
20
|
-
FileUtils.rm_rf(path.to_s)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should generate in/out fixtures in tmp/fixtures" do
|
24
|
-
path = Pathname("tmp/fixtures")
|
25
|
-
data = {:a=>"a", :b=>"b", :x=>1, :y=>2}
|
26
|
-
opts = {:save_fixture=>true}
|
27
|
-
|
28
|
-
truncate(path)
|
29
|
-
TSFC.execute(data.merge(opts))
|
30
|
-
|
31
|
-
load_yaml(path + "tsfc/in.yaml" ).should == {:a=>"a"}
|
32
|
-
load_yaml(path + "tsfc/out.yaml").should == {:x=>10}
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should generate in/out fixtures in <save_fixture_dir>" do
|
36
|
-
path = Pathname("tmp/test/fixtures")
|
37
|
-
data = {:a=>"a", :b=>"b", :x=>1, :y=>2}
|
38
|
-
opts = {:save_fixture=>true, :save_fixture_dir=>path}
|
39
|
-
|
40
|
-
truncate(path)
|
41
|
-
TSFC.execute(data.merge(opts))
|
42
|
-
|
43
|
-
load_yaml(path + "tsfc/in.yaml" ).should == {:a=>"a"}
|
44
|
-
load_yaml(path + "tsfc/out.yaml").should == {:x=>10}
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|