social_snippet 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mzg5Mjk4NTRjY2Q5YTA0NTJjMGUxOWM5NGJjYzFkMDcwZjYxYWNjOA==
4
+ NThkYzM3YjZlNGFlNTRhMWY4ODBiOTZlZDU1Y2E3Njg5MjBkMWI2ZA==
5
5
  data.tar.gz: !binary |-
6
- M2Q0NjlhNzU1YWViYTg3OGJiNjJiNWNmMzExZGEwYzQ2YjQ0ZWUzMg==
6
+ OTVhNjZmMGIxZDAwOWRlOTdlNjcyZjEyNWY4Njk5MWRkNjE0NzM2Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Mzc0MDUxM2VmMmZlYjczNjc0NzQ0N2I5ZThiZWMxMmZiNzY3OTYzNzUzODNh
10
- NDQyNzgzMTU1NmUzMDhiNmNhZGZiYjM3ZjEzZWJmNmFlOTRkNjkzZjIwMTEw
11
- NTNhYzQyMjZiOWIyOGZjNDZhNzQzYWQyMmNkNTlkMzE3MGRmZmM=
9
+ NGY1YjIwMzZmNGRlNmRiYjE3MDczNzhlZTA5NWQ5MmUzMDc2NmY0Y2I5YzVh
10
+ YjM0NTEyZDIyNDg0NWMyODdmMjJlZGM0YWU0NzYzYzdhMzY5ZDIyNTRhY2U4
11
+ NWVmZmEwMWUyMTAxZGM4M2Q5NjhkYTViZTkzNDE0YzA5MjVkMTE=
12
12
  data.tar.gz: !binary |-
13
- MGRlZDc4ODRjNWQ0N2RkNTQ1M2JiOTJlZTg1NTU3OWM0ZjA2NzQ4YmM2Yzk1
14
- NTE5YTA3ZDk0NDA3NmI4NmM3YThkYWM4YzUxYzdlNjM2ZjUzOWU2NDBjNTJl
15
- ZjM4MTBmMzJkZWQ2N2U0Mzc2ZjkzNzRhOTZhNWEyNWM5MDQwMmQ=
13
+ YWIxMDE1ZGQ3ZjAwNGZjMjg5Y2FkNTljMDk3ODgzODhhMWEwMzU5ODZjYzYy
14
+ OWRkMjJkYWMyZWZkM2RiNDdhOGJhNjA3MWI5ZjhkMzFmNzMzNmU4OTcwZWI5
15
+ ZWUyODMxZmNjY2NkMTMwZDE1YTM5NzYwYmEyZDhjNzhhOTYxOGM=
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Social Snippet
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/social_snippet.svg)](http://badge.fury.io/rb/social_snippet)
4
- [![Build Status](https://travis-ci.org/social-snippet/social-snippet.svg?branch=master)](https://travis-ci.org/social-snippet/social-snippet)
5
- [![Code Climate](https://codeclimate.com/github/social-snippet/social-snippet/badges/gpa.svg)](https://codeclimate.com/github/social-snippet/social-snippet)
6
- [![Test Coverage](https://codeclimate.com/github/social-snippet/social-snippet/badges/coverage.svg)](https://codeclimate.com/github/social-snippet/social-snippet)
3
+ [![Gem Version](https://img.shields.io/gem/v/social_snippet.svg)](https://rubygems.org/gems/social_snippet)
4
+ [![Build Status](https://img.shields.io/travis/social-snippet/social-snippet.svg)](https://travis-ci.org/social-snippet/social-snippet)
5
+ [![Code Climate](https://img.shields.io/codeclimate/github/social-snippet/social-snippet.svg)](https://codeclimate.com/github/social-snippet/social-snippet)
6
+ [![Test Coverage](https://img.shields.io/codeclimate/coverage/github/social-snippet/social-snippet.svg)](https://codeclimate.com/github/social-snippet/social-snippet)
7
7
 
8
8
  TODO: Write a gem description
9
9
 
data/Rakefile CHANGED
@@ -3,9 +3,13 @@ require "bundler/gem_tasks"
3
3
 
4
4
  task :default => [:spec]
5
5
 
6
+
7
+ #
8
+ # Testing
9
+ #
10
+
6
11
  require "rspec/core/rake_task"
7
12
 
8
- # rake spec
9
13
  RSpec::Core::RakeTask.new(:spec) do |t|
10
14
  ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
11
15
  t.rspec_opts = [
@@ -15,7 +19,16 @@ RSpec::Core::RakeTask.new(:spec) do |t|
15
19
  ]
16
20
  end
17
21
 
18
- # rake spec_without_fs
22
+ RSpec::Core::RakeTask.new(:spec_current) do |t|
23
+ ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
24
+ t.rspec_opts = [
25
+ "--format documentation",
26
+ "--color",
27
+ "--tag ~without_fakefs",
28
+ "--tag current",
29
+ ]
30
+ end
31
+
19
32
  RSpec::Core::RakeTask.new(:spec_without_fakefs) do |t|
20
33
  ENV["RSPEC_WITHOUT_FAKEFS"] = "true"
21
34
  t.rspec_opts = [
@@ -25,7 +38,6 @@ RSpec::Core::RakeTask.new(:spec_without_fakefs) do |t|
25
38
  ]
26
39
  end
27
40
 
28
- # rake test
29
41
  RSpec::Core::RakeTask.new(:test) do |t|
30
42
  ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
31
43
  t.rspec_opts = [
@@ -35,7 +47,16 @@ RSpec::Core::RakeTask.new(:test) do |t|
35
47
  ]
36
48
  end
37
49
 
38
- # rake test_without_fakefs
50
+ RSpec::Core::RakeTask.new(:test_current) do |t|
51
+ ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
52
+ t.rspec_opts = [
53
+ "--pattern '../test/*_test.rb'",
54
+ "--color",
55
+ "--tag ~without_fakefs",
56
+ "--tag current",
57
+ ]
58
+ end
59
+
39
60
  RSpec::Core::RakeTask.new(:test_without_fakefs) do |t|
40
61
  ENV["RSPEC_WITHOUT_FAKEFS"] = "true"
41
62
  t.rspec_opts = [
@@ -45,6 +66,11 @@ RSpec::Core::RakeTask.new(:test_without_fakefs) do |t|
45
66
  ]
46
67
  end
47
68
 
69
+
70
+ #
71
+ # Documentation
72
+ #
73
+
48
74
  require "yard"
49
75
  require "yard/rake/yardoc_task"
50
76
 
data/appveyor.yml CHANGED
@@ -2,29 +2,42 @@ version: "{build}"
2
2
 
3
3
  install:
4
4
  - ps: iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
5
- - choco install pkgconfiglite
6
- - git clone --branch v0.21.1 --depth 1 --single-branch git://github.com/libgit2/libgit2 libgit2
7
- - cd libgit2
8
- - cmake -DCMAKE_BUILD_TYPE=Release -DTHREADSAFE=ON -DBUILD_CLAR=OFF -DCMAKE_INSTALL_PREFIX=%PREFIX%\libgit2 .
9
- - cmake --build . --target install
10
-
11
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
12
- - ruby --version
13
- - SET PATH=%PREFIX%\libgit2\bin;%PATH%
14
-
15
- - gem update --system
5
+ - cmd: choco install pkgconfiglite
6
+ - cmd: if not exist c:\src\libgit2 git clone --branch v0.21.1 --depth 1 --single-branch git://github.com/libgit2/libgit2 c:\src\libgit2
7
+ - cmd: cd c:\src\libgit2
8
+ - cmd: cmake -DCMAKE_BUILD_TYPE=Release -DTHREADSAFE=ON -DBUILD_CLAR=OFF -DCMAKE_INSTALL_PREFIX=%PREFIX%\libgit2 .
9
+ - cmd: cmake --build . --target install
10
+
11
+ - cmd: SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
12
+ - cmd: ruby --version
13
+ - cmd: SET PATH=%PREFIX%\libgit2\bin;%PATH%
14
+
15
+ - cmd: gem --version
16
+ - cmd: gem update --system
16
17
  - gem install rugged --no-ri --no-rdoc -- --use-system-libraries --with-git2-dir=%PREFIX%\libgit2
17
- - gem install bundler --no-ri --no-rdoc
18
- - bundle install --jobs 2
18
+ # - gem install bundler --no-ri --no-rdoc
19
+ # - bundle install --jobs 2
19
20
 
20
21
  test_script:
21
- - cmd: bundle exec rake spec
22
- - cmd: bundle exec rake spec_without_fakefs
23
- - cmd: bundle exec rake test
24
- - cmd: bundle exec rake test_without_fakefs
22
+ - cmd: echo starting test...
23
+ # - cmd: bundle exec rake spec
24
+ # - cmd: bundle exec rake spec_without_fakefs
25
+ # - cmd: bundle exec rake test
26
+ # - cmd: bundle exec rake test_without_fakefs
25
27
 
26
28
  build: off
27
29
 
30
+ cache:
31
+ - c:\src
32
+ - c:\libs
33
+ - vendor/bundle
34
+ - C:\Ruby193\lib\ruby\gems\1.9.1
35
+ - C:\Ruby193\bin
36
+ - C:\Ruby200\lib\ruby\gems\2.0.0
37
+ - C:\Ruby200\bin
38
+ - C:\Ruby21\lib\ruby\gems\2.1.0
39
+ - C:\Ruby21\bin
40
+
28
41
  environment:
29
42
 
30
43
  global:
@@ -32,5 +45,5 @@ environment:
32
45
 
33
46
  matrix:
34
47
  - ruby_version: "21"
35
- - ruby_version: "20"
36
- - ruby_version: "19"
48
+ # - ruby_version: "200"
49
+ # - ruby_version: "193"
@@ -9,6 +9,15 @@ class SocialSnippet::Api
9
9
  @social_snippet = new_social_snippet
10
10
  end
11
11
 
12
+ def config_set(key, value)
13
+ social_snippet.config.set! key, value
14
+ end
15
+
16
+ def config_get(key)
17
+ value = social_snippet.config.get(key)
18
+ social_snippet.logger.say "#{key}=#{value}"
19
+ end
20
+
12
21
  # Insert snippets to given text
13
22
  #
14
23
  # @param src [String] The text of source code
@@ -0,0 +1,53 @@
1
+ module SocialSnippet::CommandLine
2
+
3
+ class SSpm::SubCommands::ConfigCommand < Command
4
+
5
+ def usage
6
+ <<EOF
7
+ Usage:
8
+ $ sspm config <key>
9
+ -> show <value>
10
+
11
+ $ sspm config <key>=<value>
12
+ $ sspm config <key> <value>
13
+ -> set <value> to key
14
+ EOF
15
+ end
16
+
17
+ def desc
18
+ "Manage configuration"
19
+ end
20
+
21
+ def define_options
22
+ end
23
+
24
+ def run
25
+ if has_next_token?
26
+ s = next_token
27
+ if has_next_token?
28
+ key = s
29
+ value = next_token
30
+ social_snippet.api.config_set key, value
31
+ else
32
+ if has_value?(s)
33
+ key, value = s.split("=")
34
+ social_snippet.api.config_set key, value
35
+ else
36
+ key = s
37
+ social_snippet.api.config_get key
38
+ end
39
+ end
40
+ else
41
+ help
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def has_value?(s)
48
+ /=/ === s
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -14,3 +14,4 @@ require_relative "sub_commands/complete_command"
14
14
  require_relative "sub_commands/info_command"
15
15
  require_relative "sub_commands/update_command"
16
16
  require_relative "sub_commands/publish_command"
17
+ require_relative "sub_commands/config_command"
@@ -1,13 +1,15 @@
1
1
  class SocialSnippet::Config
2
2
 
3
+ require "json"
4
+
3
5
  attr_reader :social_snippet
6
+ attr_reader :home
7
+ attr_reader :fields
4
8
 
5
9
  # prefix of environment variables
6
10
  ENV_PREFIX = "SOCIAL_SNIPPET_"
7
11
 
8
- FIELDS = [
9
- # The path of home directory [default: "$HOME/.social-snippet"]
10
- :home,
12
+ ENV_FIELDS = [
11
13
  # Enable debug mode? [default: false]
12
14
  :debug,
13
15
  # Web API host [default: "sspm.herokuapp.com"]
@@ -19,33 +21,77 @@ class SocialSnippet::Config
19
21
  ]
20
22
 
21
23
  # use "true" / "false"
22
- FLAGS = [
24
+ ENV_FLAGS = [
23
25
  :debug,
24
26
  ]
25
27
 
26
- # set accessors
27
- FIELDS.each {|field| attr_reader field }
28
-
29
28
  # Constructor
30
29
  def initialize(new_social_snippet, options = {})
31
30
  @social_snippet = new_social_snippet
31
+ @fields = {}
32
+ resolve_home
32
33
 
33
- fields = {}
34
- fields.merge! options
35
- load_environment_variables fields
34
+ # env vars > args > config.json
35
+ init_directories
36
+ load_file
37
+ load_options options
38
+ load_environment_variables
36
39
 
37
40
  # set default values
38
- fields[:home] ||= "#{ENV["HOME"]}/.social-snippet"
39
- fields[:sspm_host] ||= "sspm.herokuapp.com"
40
- fields[:sspm_version] ||= "v0"
41
- fields[:sspm_protocol] ||= "https"
41
+ set_default :sspm_host, "sspm.herokuapp.com"
42
+ set_default :sspm_version, "v0"
43
+ set_default :sspm_protocol, "https"
42
44
 
43
- FIELDS.each do |field_name|
45
+ ENV_FIELDS.each do |field_name|
44
46
  key = "@#{field_name.to_s}".to_sym
45
47
  instance_variable_set key, fields[field_name]
46
48
  end
47
49
 
48
- init_directories
50
+ save_file
51
+ end
52
+
53
+ def set_default(key, value)
54
+ key = normalize_key(key)
55
+ fields[key] ||= value
56
+ end
57
+
58
+ # Set value
59
+ def set(key, value)
60
+ key = normalize_key(key)
61
+ fields[key] = value
62
+ end
63
+
64
+ # Set value and save to file
65
+ def set!(key, value)
66
+ set(key, value)
67
+ save_file
68
+ end
69
+
70
+ def get(key)
71
+ key = normalize_key(key)
72
+ fields[key]
73
+ end
74
+
75
+ def save_file
76
+ @fields ||= {}
77
+ ::File.write file_path, fields.to_json
78
+ end
79
+
80
+ def load_file
81
+ begin
82
+ @fields = ::JSON.parse(::File.read file_path)
83
+ rescue ::JSON::ParserError
84
+ raise "error on parsing #{file_path}"
85
+ end
86
+ end
87
+
88
+
89
+ #
90
+ # config helpers
91
+ #
92
+
93
+ def file_path
94
+ ::File.join home, "config.json"
49
95
  end
50
96
 
51
97
  def repository_cache_path
@@ -60,21 +106,33 @@ class SocialSnippet::Config
60
106
  ::File.join home, "repo"
61
107
  end
62
108
 
109
+ def sspm_url
110
+ "#{get :sspm_protocol}://#{get :sspm_host}/api/#{get :sspm_version}"
111
+ end
112
+
113
+ def debug?
114
+ get :debug
115
+ end
116
+
63
117
  def init_directories
64
118
  ::FileUtils.mkdir_p home
65
119
  ::FileUtils.mkdir_p install_path
66
120
  ::FileUtils.mkdir_p repository_cache_path
67
- end
68
-
69
- def debug?
70
- debug
121
+ ::File.write file_path, {}.to_json unless ::File.exists?(file_path)
71
122
  end
72
123
 
73
124
  private
74
125
 
75
- def load_environment_variables(fields)
76
- FIELDS.each do |field_sym|
77
- fields[field_sym] ||= load_env(field_sym)
126
+ # Key => key
127
+ # :Key => key
128
+ def normalize_key(key)
129
+ key.to_s.downcase
130
+ end
131
+
132
+ def load_environment_variables
133
+ ENV_FIELDS.each do |field_sym|
134
+ value = load_env(field_sym)
135
+ set field_sym, value unless value.nil?
78
136
  end
79
137
  end
80
138
 
@@ -82,11 +140,22 @@ class SocialSnippet::Config
82
140
  name = sym.to_s.upcase # :foo_bar => FOO_BAR
83
141
  key = "#{ENV_PREFIX}#{name}"
84
142
  return nil unless ENV.has_key?(key) && (not ENV[key].nil?)
85
- if FLAGS.include?(sym)
143
+ if ENV_FLAGS.include?(sym)
86
144
  ENV[key] === "true"
87
145
  else
88
146
  ENV[key]
89
147
  end
90
148
  end
91
149
 
150
+ def load_options(options)
151
+ options.each do |key, value|
152
+ set key, value
153
+ end
154
+ end
155
+
156
+ def resolve_home
157
+ @home ||= ENV["SOCIAL_SNIPPET_HOME"]
158
+ @home ||= ::File.join(ENV["HOME"], ".social-snippet")
159
+ end
160
+
92
161
  end
@@ -7,19 +7,13 @@ module SocialSnippet::Registry::RegistryResources
7
7
 
8
8
  attr_reader :social_snippet
9
9
  attr_reader :rest_client
10
- attr_reader :protocol
11
- attr_reader :host
12
- attr_reader :api_version
13
10
  attr_reader :end_point
14
11
  attr_reader :cookies
15
12
  attr_reader :default_headers
16
13
 
17
14
  def initialize(new_social_snippet)
18
15
  @social_snippet = new_social_snippet
19
- @host = social_snippet.config.sspm_host
20
- @api_version = social_snippet.config.sspm_version
21
- @protocol = social_snippet.config.sspm_protocol
22
- @end_point = "#{protocol}://#{host}/api/#{api_version}"
16
+ @end_point = social_snippet.config.sspm_url
23
17
  @rest_client = ::RestClient::Resource.new(end_point)
24
18
  @cookies = {}
25
19
  @default_headers = {
@@ -1,6 +1,6 @@
1
1
  module SocialSnippet
2
2
 
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
 
5
5
  module Version
6
6
 
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ module SocialSnippet::CommandLine
4
+
5
+ describe SSpm::SubCommands::ConfigCommand, :current => true do
6
+
7
+ describe "$ sspm config key" do
8
+
9
+ let(:sspm_config_command) { SSpm::SubCommands::ConfigCommand.new ["key"] }
10
+
11
+ it { expect(fake_social_snippet.api).to receive(:config_get).with("key").once }
12
+
13
+ after do
14
+ sspm_config_command.init
15
+ sspm_config_command.run
16
+ end
17
+
18
+ end
19
+
20
+ describe "$ sspm config key value" do
21
+
22
+ let(:sspm_config_command) { SSpm::SubCommands::ConfigCommand.new ["key", "value"] }
23
+
24
+ it { expect(fake_social_snippet.api).to receive(:config_set).with("key", "value").once }
25
+
26
+ after do
27
+ sspm_config_command.init
28
+ sspm_config_command.run
29
+ end
30
+
31
+ end
32
+
33
+ describe "$ sspm config key=value" do
34
+
35
+ let(:sspm_config_command) { SSpm::SubCommands::ConfigCommand.new ["key=value"] }
36
+
37
+ it { expect(fake_social_snippet.api).to receive(:config_set).with("key", "value").once }
38
+
39
+ after do
40
+ sspm_config_command.init
41
+ sspm_config_command.run
42
+ end
43
+
44
+ end
45
+
46
+ end # SSpm::MainCommand
47
+
48
+ end # SocialSnippet::CommandLine
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe SocialSnippet::Config, :without_fakefs => $WITHOUT_FAKEFS do
3
+ describe SocialSnippet::Config, :without_fakefs => $WITHOUT_FAKEFS, :current => true do
4
4
 
5
5
  let(:logger) do
6
6
  logger = ::SocialSnippet::Logger.new(STDOUT)
@@ -8,49 +8,110 @@ describe SocialSnippet::Config, :without_fakefs => $WITHOUT_FAKEFS do
8
8
  logger
9
9
  end
10
10
 
11
- let(:config) do
12
- ::SocialSnippet::Config.new(social_snippet)
13
- end
14
-
15
11
  let(:social_snippet) do
16
12
  class Fake; end
17
13
  Fake.new
18
14
  end
19
15
 
20
- describe "#new" do
16
+ let(:config) do
17
+ ::SocialSnippet::Config.new(social_snippet)
18
+ end
19
+
20
+ before { stub_const "ENV", "HOME" => Dir.mktmpdir }
21
+
22
+ describe "sspm_url" do
21
23
 
22
- before { stub_const "ENV", "HOME" => Dir.mktmpdir }
24
+ context "set info" do
25
+ before { config.set :sspm_host, "api.test" }
26
+ before { config.set :sspm_protocol, "https" }
27
+ before { config.set :sspm_version, "v0" }
28
+ it { expect(config.sspm_url).to eq "https://api.test/api/v0" }
29
+ end
23
30
 
24
- context "use default value" do
31
+ end # sspm_url
25
32
 
26
- let(:config) do
27
- ::SocialSnippet::Config.new(social_snippet)
33
+ describe "getter / setter" do
34
+
35
+ context "get undefined key" do
36
+ it { expect(config.get "this-is-undefined").to be_nil }
37
+ end
38
+
39
+ context "set key without saving" do
40
+
41
+ before { config.set "key", "value1" }
42
+
43
+ context "get key" do
44
+ it { expect(config.get "key").to eq "value1" }
28
45
  end
29
46
 
30
- context "#home" do
31
- subject { config.home }
32
- it { should eq "#{ENV["HOME"]}/.social-snippet" }
47
+ context "reload file" do
48
+
49
+ before { config.load_file }
50
+
51
+ context "get key" do
52
+ it { expect(config.get "key").to be_nil }
53
+ end
54
+
33
55
  end
34
56
 
35
- end # use default value
57
+ end # set key without saving
58
+
59
+ context "set key with saving" do
36
60
 
37
- context "set ENV[SOCIAL_SNIPPET_HOME]" do
61
+ describe "set!()" do
38
62
 
39
- before { stub_const "ENV", "SOCIAL_SNIPPET_HOME" => Dir.mktmpdir }
63
+ before { config.set! "key", "value" }
64
+
65
+ context "reload file" do
66
+
67
+ before { config.load_file }
68
+
69
+ context "get key" do
70
+ it { expect(config.get "key").to eq "value" }
71
+ end
72
+
73
+ end
40
74
 
41
- let(:config) do
42
- ::SocialSnippet::Config.new(social_snippet)
43
75
  end
44
76
 
45
- context "#home" do
46
- subject { config.home }
47
- it { should_not eq "#{ENV["HOME"]}/.social-snippet" }
48
- it { should eq ENV["SOCIAL_SNIPPET_HOME"] }
77
+ describe "save_file()" do
78
+
79
+ before do
80
+ config.set "key", "value"
81
+ config.save_file
82
+ end
83
+
84
+ context "reload file" do
85
+
86
+ before { config.load_file }
87
+
88
+ context "get key" do
89
+ it { expect(config.get "key").to eq "value" }
90
+ end
91
+
92
+ end
93
+
49
94
  end
50
95
 
51
- end # set ENV[SOCIAL_SNIPPET_HOME]
96
+ end # set key with saving
97
+
98
+ end # getter / setter
99
+
100
+ describe "use default value" do
101
+
102
+ it { expect(config.home).to eq ::File.join(ENV["HOME"], ".social-snippet") }
103
+ it { expect(config.file_path).to eq ::File.join(ENV["HOME"], ".social-snippet", "config.json") }
104
+
105
+ end # use default value
106
+
107
+ context "set ENV[SOCIAL_SNIPPET_HOME]" do
108
+
109
+ before { stub_const "ENV", "HOME" => Dir.mktmpdir, "SOCIAL_SNIPPET_HOME" => Dir.mktmpdir }
110
+ it { expect(config.home).to_not eq ::File.join(ENV["HOME"], ".social-snippet") }
111
+ it { expect(config.home).to eq ENV["SOCIAL_SNIPPET_HOME"] }
112
+ it { expect(config.file_path).to eq ::File.join(ENV["SOCIAL_SNIPPET_HOME"], "config.json") }
52
113
 
53
- end # new
114
+ end # set ENV[SOCIAL_SNIPPET_HOME]
54
115
 
55
116
  end # SocialSnippet::Config
56
117
 
@@ -18,16 +18,11 @@ module SocialSnippet
18
18
  end
19
19
 
20
20
  let(:config) do
21
- config = Config.new(
22
- social_snippet,
23
- {
24
- :sspm_host => "api.server",
25
- :sspm_version => "v0",
26
- :sspm_protocol => "http",
27
- }
28
- )
21
+ Config.new social_snippet
29
22
  end
30
23
 
24
+ before { allow(config).to receive(:sspm_url).and_return "http://api.server/api/v0" }
25
+
31
26
  def logger
32
27
  ::Logger.new(::StringIO.new)
33
28
  end
@@ -63,12 +63,12 @@ module SocialSnippet::Repository::Drivers
63
63
 
64
64
  describe "#commit_id" do
65
65
  subject { repo.commit_id }
66
- it { should eq "073f4411f5251745b339d57356e2560f386e268c" }
66
+ it { should eq "38ebf733622174e24d76d28ab264c52b4fd7bda9" }
67
67
  end
68
68
 
69
69
  describe "#short_commit_id" do
70
70
  subject { repo.short_commit_id }
71
- it { should eq "073f4411" }
71
+ it { should eq "38ebf733" }
72
72
  end
73
73
 
74
74
  end # checkout 1.0.x
@@ -0,0 +1,84 @@
1
+ require "spec_helper"
2
+
3
+ describe SocialSnippet::Config, :without_fakefs => $WITHOUT_FAKEFS, :current => true do
4
+
5
+ let(:logger) do
6
+ logger = ::SocialSnippet::Logger.new(STDOUT)
7
+ logger.level = ::SocialSnippet::Logger::Severity::UNKNOWN
8
+ logger
9
+ end
10
+
11
+ let(:social_snippet) do
12
+ class Fake; end
13
+ Fake.new
14
+ end
15
+
16
+ let(:config) do
17
+ ::SocialSnippet::Config.new(social_snippet)
18
+ end
19
+
20
+ before { stub_const "ENV", "HOME" => Dir.mktmpdir }
21
+
22
+ describe "priority" do
23
+
24
+ example do
25
+ conf = ::SocialSnippet::Config.new(
26
+ social_snippet,
27
+ {
28
+ :sspm_host => "this.is.host",
29
+ :sspm_protocol => "proto",
30
+ :sspm_version => "version",
31
+ }
32
+ )
33
+ expect(conf.sspm_url).to eq "proto://this.is.host/api/version"
34
+ end
35
+
36
+ end
37
+
38
+ describe "case insensitivility" do
39
+
40
+ context "set key" do
41
+ before { config.set "key", "value" }
42
+ it { expect(config.get "key").to eq "value" }
43
+ it { expect(config.get "Key").to eq "value" }
44
+ it { expect(config.get "KEY").to eq "value" }
45
+ end
46
+
47
+ context "set Key" do
48
+ before { config.set "Key", "value" }
49
+ it { expect(config.get "key").to eq "value" }
50
+ it { expect(config.get "Key").to eq "value" }
51
+ it { expect(config.get "KEY").to eq "value" }
52
+ end
53
+
54
+ context "set KEY" do
55
+ before { config.set "KEY", "value" }
56
+ it { expect(config.get "key").to eq "value" }
57
+ it { expect(config.get "Key").to eq "value" }
58
+ it { expect(config.get "KEY").to eq "value" }
59
+ end
60
+
61
+ context "set! key" do
62
+ before { config.set! "key", "value" }
63
+ it { expect(config.get "key").to eq "value" }
64
+ it { expect(config.get "Key").to eq "value" }
65
+ it { expect(config.get "KEY").to eq "value" }
66
+ end
67
+
68
+ context "set! Key" do
69
+ before { config.set! "Key", "value" }
70
+ it { expect(config.get "key").to eq "value" }
71
+ it { expect(config.get "Key").to eq "value" }
72
+ it { expect(config.get "KEY").to eq "value" }
73
+ end
74
+
75
+ context "set! KEY" do
76
+ before { config.set! "KEY", "value" }
77
+ it { expect(config.get "key").to eq "value" }
78
+ it { expect(config.get "Key").to eq "value" }
79
+ it { expect(config.get "KEY").to eq "value" }
80
+ end
81
+
82
+ end # case insensitivility
83
+
84
+ end
@@ -27,7 +27,7 @@ describe ::SocialSnippet::Repository::RepositoryManager do
27
27
  ::SocialSnippet::Repository::RepositoryManager.new(social_snippet)
28
28
  end
29
29
 
30
- describe "complete (repo)", :current => true do
30
+ describe "complete (repo)" do
31
31
 
32
32
  before do
33
33
  install_path = "/path/to/install/path"
@@ -53,7 +53,7 @@ describe ::SocialSnippet::Repository::RepositoryManager do
53
53
 
54
54
  end # complete (repo)
55
55
 
56
- describe "is_completing_file_path?", :current => true do
56
+ describe "is_completing_file_path?" do
57
57
 
58
58
  context "valid cases" do
59
59
  it { expect(repo_manager.is_completing_file_path? "// @snip <repo:").to be_truthy }
@@ -83,7 +83,7 @@ describe ::SocialSnippet::Repository::RepositoryManager do
83
83
 
84
84
  end # is_completing_repo_name?
85
85
 
86
- describe "is_completing_repo_name?", :current => true do
86
+ describe "is_completing_repo_name?" do
87
87
 
88
88
  context "valid cases" do
89
89
  it { expect(repo_manager.is_completing_repo_name? "@snip <repo").to be_truthy }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_snippet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki Sano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-31 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -235,6 +235,7 @@ files:
235
235
  - lib/social_snippet/command_line/sspm/main_command.rb
236
236
  - lib/social_snippet/command_line/sspm/sub_commands.rb
237
237
  - lib/social_snippet/command_line/sspm/sub_commands/complete_command.rb
238
+ - lib/social_snippet/command_line/sspm/sub_commands/config_command.rb
238
239
  - lib/social_snippet/command_line/sspm/sub_commands/info_command.rb
239
240
  - lib/social_snippet/command_line/sspm/sub_commands/install_command.rb
240
241
  - lib/social_snippet/command_line/sspm/sub_commands/publish_command.rb
@@ -271,6 +272,7 @@ files:
271
272
  - spec/helpers/fakefs_helper.rb
272
273
  - spec/helpers/webmock_helper.rb
273
274
  - spec/lib/api_spec.rb
275
+ - spec/lib/command_line/sspm_config_spec.rb
274
276
  - spec/lib/command_line/sspm_install_spec.rb
275
277
  - spec/lib/command_line/sspm_search_spec.rb
276
278
  - spec/lib/command_line/sspm_spec.rb
@@ -289,6 +291,7 @@ files:
289
291
  - spec/spec_helper.rb
290
292
  - test/base_repository_test.rb
291
293
  - test/command_test.rb
294
+ - test/config_test.rb
292
295
  - test/context_test.rb
293
296
  - test/core_test.rb
294
297
  - test/git_repository_test.rb
@@ -326,6 +329,7 @@ test_files:
326
329
  - spec/helpers/fakefs_helper.rb
327
330
  - spec/helpers/webmock_helper.rb
328
331
  - spec/lib/api_spec.rb
332
+ - spec/lib/command_line/sspm_config_spec.rb
329
333
  - spec/lib/command_line/sspm_install_spec.rb
330
334
  - spec/lib/command_line/sspm_search_spec.rb
331
335
  - spec/lib/command_line/sspm_spec.rb
@@ -344,6 +348,7 @@ test_files:
344
348
  - spec/spec_helper.rb
345
349
  - test/base_repository_test.rb
346
350
  - test/command_test.rb
351
+ - test/config_test.rb
347
352
  - test/context_test.rb
348
353
  - test/core_test.rb
349
354
  - test/git_repository_test.rb