scribbler 0.2.3 → 0.3.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.
@@ -1,3 +1,3 @@
1
1
  module Scribbler
2
- VERSION = '0.2.3'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |gem|
21
21
  gem.add_development_dependency 'rake'
22
22
  gem.add_development_dependency 'rspec'
23
23
  gem.add_development_dependency 'awesome_print'
24
+ gem.add_development_dependency 'simplecov'
24
25
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ module Scribbler
4
+ describe Base do
5
+ subject { described_class }
6
+
7
+ describe "configure" do
8
+ it "sets some config variables" do
9
+ subject.configure do
10
+ config.application_include = true
11
+ end
12
+ subject.config.application_include.should be_true
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Scribbler
4
- describe CLI do
5
- subject { CLI }
4
+ describe CLIClient do
6
5
  let(:cp_command) { 'cp x y' }
7
6
  describe '.run_command' do
8
7
  it 'calls backtick command with output' do
@@ -21,15 +20,16 @@ module Scribbler
21
20
  describe '.say' do
22
21
  it 'calls puts wth the param' do
23
22
  subject.should_receive(:puts).with("Boom")
24
- subject.say "Boom"
23
+ subject.send :say, "Boom"
25
24
  end
26
25
  end
27
26
 
28
27
  describe '.mass_copy' do
29
28
  let(:file_list) { ["/tmp/fake_file_1", "/tmp/fake_file 2"] }
30
29
  let(:destination) { "/tmp/destination" }
30
+ let(:out_definitions) { subject.send :out_definitions }
31
31
  it "copies all the files to the destination" do
32
- subject.should_receive(:output).with('cp').once
32
+ subject.should_receive(:say).with(out_definitions['cp']).once
33
33
  subject.should_receive(:run_command).with("cp #{file_list[0]} #{destination}", :output => false).once
34
34
  subject.should_receive(:run_command).with("cp #{file_list[1]} #{destination}", :output => false).once
35
35
  subject.mass_copy file_list, destination
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
+ module Rails; end
3
4
  module Scribbler
4
5
  describe Configurator do
5
- subject { Configurator }
6
6
  describe "logs" do
7
7
  it "lets me set logs" do
8
8
  new_logs = %w{1 2}
@@ -22,11 +22,22 @@ module Scribbler
22
22
  end
23
23
  end
24
24
 
25
+ describe "default template" do
26
+ its(:template) { should be_a Proc }
27
+ end
28
+
25
29
  describe "log directory" do
30
+ let(:root_stub) { double }
31
+ before do
32
+ Rails.stub :root => root_stub
33
+ end
34
+
35
+ after do
36
+ Rails.rspec_reset
37
+ end
38
+
26
39
  it "tries a rails root when Rails defined" do
27
- root_stub = stub
28
40
  root_stub.should_receive(:join).with 'log'
29
- Rails = stub(:root => root_stub)
30
41
  subject.log_directory
31
42
  end
32
43
 
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Scribbler
4
+ describe Executable do
5
+ its(:cli) { should be_a CLIClient }
6
+ describe "stubbed CLI Client" do
7
+ let(:cli) { double }
8
+ let(:config) { Scribbler.config }
9
+ before do
10
+ subject.stub cli: cli
11
+ end
12
+ describe '.install' do
13
+ it 'runs some CLI commands' do
14
+ cli.should_receive(:run_command).with("mkdir -p #{config.default_install_path}")
15
+ cli.should_receive(:mass_copy).with(config.templates, config.default_install_path)
16
+ subject.install
17
+ end
18
+
19
+ let(:custom_path) { '/some/custom/path' }
20
+ it 'runs changes install path with given option' do
21
+ cli.should_receive(:run_command).with("mkdir -p #{custom_path}")
22
+ cli.should_receive(:mass_copy).with(config.templates, custom_path)
23
+ subject.install :path => custom_path
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ module Scribbler
3
+ class IncludedTest
4
+ include Includeables
5
+ end
6
+
7
+ describe IncludedTest do
8
+ subject { IncludedTest }
9
+ it { should respond_to :subseason_log_location }
10
+ it { should respond_to :production_log_location }
11
+ it { should respond_to :trees_log_location }
12
+
13
+ its(:subseason_log_location) { should be_a Pathname }
14
+
15
+ it "can call log_at manually" do
16
+ subject.log_at(:subseason).should be_a Pathname
17
+ end
18
+
19
+ it "logs via Logger" do
20
+ Logger.should_receive :log
21
+ subject.log :location, {}
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ module Scribbler
3
+ describe LogLocation do
4
+ its(:config) { should be_a Configurator }
5
+
6
+ it "builds a basic path" do
7
+ relative_path = subject.find_path(:subseason).to_s.split("/")[-3..-1].join("/")
8
+ relative_path.should == "scribbler/log/subseason.log"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,172 @@
1
+ require 'spec_helper'
2
+
3
+ module ::Rails; end
4
+ module ::NewRelic
5
+ module Agent; end
6
+ end
7
+ module Scribbler
8
+ describe Logger do
9
+ describe "class" do
10
+ subject { Logger }
11
+
12
+ it { should respond_to :log }
13
+
14
+ it "instantiates and uses instance #log" do
15
+ Logger.any_instance.should_receive(:log).once
16
+ subject.log(:location)
17
+ end
18
+ end
19
+
20
+ describe "instance" do
21
+ subject { Logger.new location, options }
22
+ let(:location) { nil }
23
+ let(:options) { {} }
24
+ let(:file) { double puts: true }
25
+ before do
26
+ Time.stub :now => "now"
27
+ File.stub(:open).and_yield(file)
28
+ end
29
+
30
+ describe "instantiation" do
31
+ its(:location) { should be_nil }
32
+ its(:options) { should == { template: false, stack_frame: nil } }
33
+ end
34
+
35
+ describe "log" do
36
+ let(:options) { { message: "fail", error: "Lots of fails", new_relic: true } }
37
+ before do
38
+ subject.should_receive(:apply_to_log).once
39
+ end
40
+
41
+ describe "with newrelic" do
42
+ before do
43
+ ::NewRelic::Agent.should_receive(:notice_error).with(options[:error]).once
44
+ end
45
+
46
+ its(:log) { should be_nil }
47
+ end
48
+
49
+ describe "without newrelic" do
50
+ before do
51
+ ::NewRelic::Agent.stub(:notice_error) do
52
+ raise NameError
53
+ end
54
+ end
55
+
56
+ its(:log) { should be_nil }
57
+ end
58
+
59
+ describe "newrelic set to off" do
60
+ let(:options) { { message: "fail", error: "Lots of fails", new_relic: false } }
61
+ before do
62
+ ::NewRelic::Agent.should_not_receive(:notice_error)
63
+ end
64
+ end
65
+
66
+ describe "no error, new relic on" do
67
+ let(:options) { { message: "fail", new_relic: true } }
68
+ before do
69
+ ::NewRelic::Agent.should_not_receive(:notice_error)
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "apply to log" do
75
+ before do
76
+ Scribbler.configure do |config|
77
+ config.logs = %w[test_log]
78
+ end
79
+ end
80
+
81
+ after do
82
+ Scribbler.instance_variable_set "@config", nil
83
+ end
84
+
85
+ describe "nil file" do
86
+ let(:file) { double puts: nil }
87
+ it "should not work without location" do
88
+ subject.send(:apply_to_log).should be_nil
89
+ end
90
+ end
91
+
92
+ describe "no message" do
93
+ let(:file) { double puts: nil }
94
+ it "should not work without message" do
95
+ subject.should_not_receive :test_log_log_location
96
+ subject.stub location: :test_log
97
+ subject.send(:apply_to_log).should be_nil
98
+ end
99
+ end
100
+
101
+ it "should build a template and try to put it in a file" do
102
+ subject.stub location: :test_log, options: { message: "..." }
103
+ subject.send :apply_to_log
104
+ end
105
+ end
106
+
107
+ describe "build with template" do
108
+ let(:some_object) { stub(:id => "no id", :class => stub(:name => "SomeObject")) }
109
+ before :each do
110
+ Scribbler.configure do |config|
111
+ config.application_include = false
112
+ end
113
+ end
114
+
115
+ after :each do
116
+ Scribbler.instance_variable_set "@config", nil
117
+ end
118
+
119
+ it "calls log, skips templater and still works" do
120
+ subject.stub options: {
121
+ object: some_object,
122
+ template: false,
123
+ message: "test\n123"
124
+ }
125
+
126
+ subject.send(:build_with_template).should == "test\n123"
127
+ end
128
+
129
+ it "calls log and gets message with template wrapper" do
130
+ subject.stub options: {
131
+ template: true,
132
+ object: some_object,
133
+ message: <<-MSG
134
+ test
135
+ 123
136
+ MSG
137
+ }
138
+ subject.send(:build_with_template).should == <<-MSG.strip_heredoc
139
+ -------------------------------------------------
140
+ now
141
+ SomeObject: no id
142
+ test
143
+ 123
144
+
145
+ MSG
146
+ end
147
+
148
+ it "calls log and gets message with custom params" do
149
+ subject.stub options: {
150
+ template: true,
151
+ object: some_object,
152
+ custom_fields: { test1: 1, test2: 2 },
153
+ message: <<-MSG
154
+ test
155
+ 123
156
+ MSG
157
+ }
158
+ subject.send(:build_with_template).should == <<-MSG.strip_heredoc
159
+ -------------------------------------------------
160
+ now
161
+ SomeObject: no id
162
+ Test1: 1
163
+ Test2: 2
164
+ test
165
+ 123
166
+
167
+ MSG
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ describe Scribbler do
3
+ subject { Scribbler }
4
+
5
+ before do
6
+ Object.send :remove_const, :Rails if defined?(Rails) == 'constant' && Rails.class == Class
7
+ Time.stub :now => "now"
8
+ end
9
+
10
+ it "should give me a configurator" do
11
+ subject.config.should be_a Scribbler::Configurator
12
+ end
13
+
14
+ describe "include_in_application" do
15
+ it "should attempt to include to the Rails app" do
16
+ module ::Rails; end
17
+ ::Rails.stub(:application => stub(:class => stub(:parent => stub(:send => true))))
18
+ subject.stub(:config => stub(:application_include => true))
19
+ subject.include_in_application.should be_true
20
+ end
21
+
22
+ it "should return nil because it caught the NameError of Rails not existing" do
23
+ subject.stub(:config => stub(:application_include => true))
24
+ subject.include_in_application.should be_nil
25
+ end
26
+
27
+ it "should not attempt to include in app if config is false" do
28
+ subject.stub(:config => stub(:application_include => false))
29
+ subject.include_in_application.should be_nil
30
+ end
31
+ end
32
+
33
+ describe "configure" do
34
+ it "kicks off the module and sends includes" do
35
+ subject.should_receive(:include_in_application).once
36
+ subject.configure do
37
+ end
38
+ end
39
+
40
+ it "sets some config variables" do
41
+ subject.configure do |config|
42
+ config.application_include = true
43
+ end
44
+ subject.config.application_include.should be_true
45
+ end
46
+ end
47
+ end
@@ -4,6 +4,11 @@
4
4
  # loaded once.
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'simplecov'
8
+ SimpleCov.start do
9
+ add_filter '/spec/'
10
+ end
11
+
7
12
  require 'scribbler'
8
13
  require 'ap'
9
14
  require 'active_support/inflector'
@@ -11,17 +16,10 @@ require 'active_support/concern'
11
16
  Dir.glob(File.expand_path('../support/lib/**/*.rb', __FILE__)).each { |file| require file }
12
17
  include SpecUtils
13
18
 
14
- singletons = %w[Base CLI Configurator Executable]
15
19
  RSpec.configure do |config|
16
20
  config.treat_symbols_as_metadata_keys_with_true_values = true
17
21
  config.run_all_when_everything_filtered = true
18
22
  config.filter_run :focus
19
23
  config.color = true
20
- config.after(:all) do # Force a reset of some Classes
21
- project_dir = File.expand_path('../..', __FILE__)
22
- singletons.each do |s|
23
- Scribbler.send(:remove_const, s)
24
- load "#{project_dir}/lib/scribbler/#{s.downcase}.rb"
25
- end
26
- end
24
+ config.order = 'random'
27
25
  end
@@ -1,4 +1,4 @@
1
- Scribbler::Base.configure do
1
+ Scribbler.configure do |config|
2
2
  # This is like the Rails configure. This is actually a #class_eval.
3
3
  # Unless you'd like to experiment with breaking things and battling dragons,
4
4
  # please only use what we document here.
@@ -1,4 +1,4 @@
1
- Scribbler::Base.configure do
1
+ Scribbler.configure do |config|
2
2
  # This is like the Rails configure. This is actually a #class_eval.
3
3
  # Unless you'd like to experiment with breaking things and battling dragons,
4
4
  # please only use what we document here.
@@ -27,14 +27,14 @@ Scribbler::Base.configure do
27
27
  # DO PLX FIX #
28
28
  #
29
29
  # If you would rather this not be default you may set this to false. Keep
30
- # in mind, there is an option on the Base.log to enable or disable the
30
+ # in mind, there is an option on the Scribbler.log to enable or disable the
31
31
  # template on a per-call basis. (:template)
32
32
  #
33
33
  # config.use_template_by_default = true # Default: false
34
34
  #
35
35
  #
36
36
  # Don't like the default template above? Write your own proc here.
37
- # The proc is given the options hash that you give to Base.log so you're
37
+ # The proc is given the options hash that you give to Scribbler.log so you're
38
38
  # given plenty of control over what information you have to work with.
39
39
  #
40
40
  # options - Hash of options for logging on Ngin
metadata CHANGED
@@ -1,96 +1,112 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scribbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
4
  prerelease:
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jon Phenow
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-06 00:00:00.000000000 Z
12
+ date: 2013-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ none: false
21
+ prerelease: false
15
22
  name: activesupport
16
23
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
24
  requirements:
19
25
  - - ! '>='
20
26
  - !ruby/object:Gem::Version
21
27
  version: '0'
28
+ none: false
22
29
  type: :runtime
23
- prerelease: false
30
+ - !ruby/object:Gem::Dependency
24
31
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
32
  requirements:
27
33
  - - ! '>='
28
34
  - !ruby/object:Gem::Version
29
35
  version: '0'
30
- - !ruby/object:Gem::Dependency
36
+ none: false
37
+ prerelease: false
31
38
  name: thor
32
39
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
40
  requirements:
35
41
  - - ! '>='
36
42
  - !ruby/object:Gem::Version
37
43
  version: '0'
44
+ none: false
38
45
  type: :runtime
39
- prerelease: false
46
+ - !ruby/object:Gem::Dependency
40
47
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
48
  requirements:
43
49
  - - ! '>='
44
50
  - !ruby/object:Gem::Version
45
51
  version: '0'
46
- - !ruby/object:Gem::Dependency
52
+ none: false
53
+ prerelease: false
47
54
  name: rake
48
55
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
56
  requirements:
51
57
  - - ! '>='
52
58
  - !ruby/object:Gem::Version
53
59
  version: '0'
60
+ none: false
54
61
  type: :development
55
- prerelease: false
62
+ - !ruby/object:Gem::Dependency
56
63
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
64
  requirements:
59
65
  - - ! '>='
60
66
  - !ruby/object:Gem::Version
61
67
  version: '0'
62
- - !ruby/object:Gem::Dependency
68
+ none: false
69
+ prerelease: false
63
70
  name: rspec
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
73
  - - ! '>='
68
74
  - !ruby/object:Gem::Version
69
75
  version: '0'
76
+ none: false
70
77
  type: :development
71
- prerelease: false
78
+ - !ruby/object:Gem::Dependency
72
79
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
80
  requirements:
75
81
  - - ! '>='
76
82
  - !ruby/object:Gem::Version
77
83
  version: '0'
78
- - !ruby/object:Gem::Dependency
84
+ none: false
85
+ prerelease: false
79
86
  name: awesome_print
80
87
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
88
  requirements:
83
89
  - - ! '>='
84
90
  - !ruby/object:Gem::Version
85
91
  version: '0'
92
+ none: false
86
93
  type: :development
87
- prerelease: false
94
+ - !ruby/object:Gem::Dependency
88
95
  version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
89
100
  none: false
101
+ prerelease: false
102
+ name: simplecov
103
+ requirement: !ruby/object:Gem::Requirement
90
104
  requirements:
91
105
  - - ! '>='
92
106
  - !ruby/object:Gem::Version
93
107
  version: '0'
108
+ none: false
109
+ type: :development
94
110
  description: ''
95
111
  email:
96
112
  - jon.phenow@tstmedia.com
@@ -100,6 +116,7 @@ extensions: []
100
116
  extra_rdoc_files: []
101
117
  files:
102
118
  - .gitignore
119
+ - .irbrc
103
120
  - .rvmrc
104
121
  - .travis.yml
105
122
  - Gemfile
@@ -109,19 +126,23 @@ files:
109
126
  - bin/scribbler
110
127
  - lib/scribbler.rb
111
128
  - lib/scribbler/base.rb
112
- - lib/scribbler/cli.rb
129
+ - lib/scribbler/cli_client.rb
113
130
  - lib/scribbler/configurator.rb
114
131
  - lib/scribbler/executable.rb
115
132
  - lib/scribbler/includeables.rb
133
+ - lib/scribbler/log_location.rb
134
+ - lib/scribbler/logger.rb
116
135
  - lib/scribbler/version.rb
117
136
  - scribbler.gemspec
118
- - spec/scribbler/base_spec.rb
119
- - spec/scribbler/cli_spec.rb
120
- - spec/scribbler/configurator_spec.rb
121
- - spec/scribbler/executable_spec.rb
122
- - spec/scribbler/includeables_spec.rb
123
- - spec/scribbler/version_spec.rb
124
- - spec/scribbler_spec.rb
137
+ - spec/lib/scribbler/base_spec.rb
138
+ - spec/lib/scribbler/cli_client_spec.rb
139
+ - spec/lib/scribbler/configurator_spec.rb
140
+ - spec/lib/scribbler/executable_spec.rb
141
+ - spec/lib/scribbler/includeables_spec.rb
142
+ - spec/lib/scribbler/log_location_spec.rb
143
+ - spec/lib/scribbler/logger_spec.rb
144
+ - spec/lib/scribbler/version_spec.rb
145
+ - spec/lib/scribbler_spec.rb
125
146
  - spec/spec_helper.rb
126
147
  - spec/support/examples/scribbler_example.rb
127
148
  - spec/support/lib/spec_utils.rb
@@ -133,23 +154,23 @@ rdoc_options: []
133
154
  require_paths:
134
155
  - lib
135
156
  required_ruby_version: !ruby/object:Gem::Requirement
136
- none: false
137
157
  requirements:
138
158
  - - ! '>='
139
159
  - !ruby/object:Gem::Version
140
160
  version: '0'
141
161
  segments:
142
162
  - 0
143
- hash: -3735178954186904383
144
- required_rubygems_version: !ruby/object:Gem::Requirement
163
+ hash: 1283107986408181274
145
164
  none: false
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
166
  requirements:
147
167
  - - ! '>='
148
168
  - !ruby/object:Gem::Version
149
169
  version: '0'
150
170
  segments:
151
171
  - 0
152
- hash: -3735178954186904383
172
+ hash: 1283107986408181274
173
+ none: false
153
174
  requirements: []
154
175
  rubyforge_project:
155
176
  rubygems_version: 1.8.24
@@ -157,13 +178,15 @@ signing_key:
157
178
  specification_version: 3
158
179
  summary: ''
159
180
  test_files:
160
- - spec/scribbler/base_spec.rb
161
- - spec/scribbler/cli_spec.rb
162
- - spec/scribbler/configurator_spec.rb
163
- - spec/scribbler/executable_spec.rb
164
- - spec/scribbler/includeables_spec.rb
165
- - spec/scribbler/version_spec.rb
166
- - spec/scribbler_spec.rb
181
+ - spec/lib/scribbler/base_spec.rb
182
+ - spec/lib/scribbler/cli_client_spec.rb
183
+ - spec/lib/scribbler/configurator_spec.rb
184
+ - spec/lib/scribbler/executable_spec.rb
185
+ - spec/lib/scribbler/includeables_spec.rb
186
+ - spec/lib/scribbler/log_location_spec.rb
187
+ - spec/lib/scribbler/logger_spec.rb
188
+ - spec/lib/scribbler/version_spec.rb
189
+ - spec/lib/scribbler_spec.rb
167
190
  - spec/spec_helper.rb
168
191
  - spec/support/examples/scribbler_example.rb
169
192
  - spec/support/lib/spec_utils.rb