middleman-build-reporter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile +3 -0
  5. data/README.md +118 -0
  6. data/Rakefile +12 -0
  7. data/features/build_reporter.feature +21 -0
  8. data/features/custom_build_reporter_file_name.feature +6 -0
  9. data/features/extended_build_reporter.feature +12 -0
  10. data/features/json_build_reporter.feature +21 -0
  11. data/features/no_explicit_version.feature +6 -0
  12. data/features/step_definitions/git_steps.rb +19 -0
  13. data/features/step_definitions/json_reporter_file_steps.rb +31 -0
  14. data/features/step_definitions/version_steps.rb +5 -0
  15. data/features/support/env.rb +4 -0
  16. data/features/support/helpers.rb +7 -0
  17. data/fixtures/basic-app/config.rb +4 -0
  18. data/fixtures/basic-app/source/images/background.png +0 -0
  19. data/fixtures/basic-app/source/images/middleman.png +0 -0
  20. data/fixtures/basic-app/source/index.html.erb +10 -0
  21. data/fixtures/basic-app/source/javascripts/all.js +1 -0
  22. data/fixtures/basic-app/source/layouts/layout.erb +19 -0
  23. data/fixtures/basic-app/source/stylesheets/all.css +55 -0
  24. data/fixtures/basic-app/source/stylesheets/normalize.css +375 -0
  25. data/fixtures/custom-reporter-file-name/config.rb +4 -0
  26. data/fixtures/custom-reporter-file-name/source/images/background.png +0 -0
  27. data/fixtures/custom-reporter-file-name/source/images/middleman.png +0 -0
  28. data/fixtures/custom-reporter-file-name/source/index.html.erb +10 -0
  29. data/fixtures/custom-reporter-file-name/source/javascripts/all.js +1 -0
  30. data/fixtures/custom-reporter-file-name/source/layouts/layout.erb +19 -0
  31. data/fixtures/custom-reporter-file-name/source/stylesheets/all.css +55 -0
  32. data/fixtures/custom-reporter-file-name/source/stylesheets/normalize.css +375 -0
  33. data/fixtures/extended-build-reporter/.build_reporter.yml +4 -0
  34. data/fixtures/extended-build-reporter/config.rb +4 -0
  35. data/fixtures/extended-build-reporter/source/images/background.png +0 -0
  36. data/fixtures/extended-build-reporter/source/images/middleman.png +0 -0
  37. data/fixtures/extended-build-reporter/source/index.html.erb +10 -0
  38. data/fixtures/extended-build-reporter/source/javascripts/all.js +1 -0
  39. data/fixtures/extended-build-reporter/source/layouts/layout.erb +19 -0
  40. data/fixtures/extended-build-reporter/source/stylesheets/all.css +55 -0
  41. data/fixtures/extended-build-reporter/source/stylesheets/normalize.css +375 -0
  42. data/fixtures/json-reporter-file/config.rb +5 -0
  43. data/fixtures/json-reporter-file/source/images/background.png +0 -0
  44. data/fixtures/json-reporter-file/source/images/middleman.png +0 -0
  45. data/fixtures/json-reporter-file/source/index.html.erb +10 -0
  46. data/fixtures/json-reporter-file/source/javascripts/all.js +1 -0
  47. data/fixtures/json-reporter-file/source/layouts/layout.erb +19 -0
  48. data/fixtures/json-reporter-file/source/stylesheets/all.css +55 -0
  49. data/fixtures/json-reporter-file/source/stylesheets/normalize.css +375 -0
  50. data/fixtures/no-version/config.rb +3 -0
  51. data/fixtures/no-version/source/images/background.png +0 -0
  52. data/fixtures/no-version/source/images/middleman.png +0 -0
  53. data/fixtures/no-version/source/index.html.erb +10 -0
  54. data/fixtures/no-version/source/javascripts/all.js +1 -0
  55. data/fixtures/no-version/source/layouts/layout.erb +19 -0
  56. data/fixtures/no-version/source/stylesheets/all.css +55 -0
  57. data/fixtures/no-version/source/stylesheets/normalize.css +375 -0
  58. data/lib/middleman-build-reporter/extension.rb +29 -0
  59. data/lib/middleman-build-reporter/reporter.rb +68 -0
  60. data/lib/middleman-build-reporter/version.rb +5 -0
  61. data/lib/middleman-build-reporter.rb +9 -0
  62. data/lib/middleman_extension.rb +1 -0
  63. data/middleman-build-reporter.gemspec +32 -0
  64. data/spec/middleman-build-reporter/extension_spec.rb +82 -0
  65. data/spec/middleman-build-reporter/reporter_spec.rb +184 -0
  66. data/spec/spec_helper.rb +35 -0
  67. metadata +248 -0
@@ -0,0 +1,184 @@
1
+ require 'spec_helper'
2
+
3
+ describe Middleman::BuildReporter::Reporter do
4
+
5
+ let(:git_repo) { Git.open('.') }
6
+
7
+ let(:fake_details) { { 'foo' => 'bar' } }
8
+
9
+ let(:app) { middleman_app('basic-app') }
10
+
11
+ let(:reporter) do
12
+ app.set :repo_root, '.'
13
+ app.set :version, '1.2.3'
14
+ app.set :reporter_file, 'reporter'
15
+ app.set :reporter_file_formats, ['yaml']
16
+
17
+ described_class.new app
18
+ end
19
+
20
+ describe '#new' do
21
+
22
+ it 'sets an attr_accessor\'d @app instance variable to the value of the app it is passed' do
23
+ expect(reporter.app).to eq app
24
+ end
25
+
26
+ it 'sets a #repo on the app instance it is passed' do
27
+ expect(reporter.app.repo.class).to eq Git::Base
28
+ end
29
+ end
30
+
31
+ describe '#write' do
32
+
33
+ it 'writes the build details to the proper "build" file' do
34
+ allow(reporter).to receive(:details).and_return fake_details
35
+ allow(reporter.app).to receive(:reporter_file).and_return 'fake_report_file'
36
+
37
+ expect(File).to receive(:write).with('build/fake_report_file.yaml', "---\nfoo: bar\n").and_return 'fake_write_call'
38
+
39
+ reporter.write
40
+ end
41
+ end
42
+
43
+ describe '#reporter_file_path' do
44
+
45
+ it 'returns the file path to which the build details should be written' do
46
+ expect(reporter.reporter_file_path).to eq 'build/reporter'
47
+ end
48
+ end
49
+
50
+ describe '#reporter_extension_path' do
51
+
52
+ it 'returns the file path to ".build_reporter.yml" file' do
53
+ expect(reporter.reporter_extension_file_path).to eq "#{app.root}/.build_reporter.yml"
54
+ end
55
+ end
56
+
57
+ describe '#details' do
58
+
59
+ before do
60
+ Timecop.travel Time.now
61
+ end
62
+
63
+ after do
64
+ Timecop.return
65
+ end
66
+
67
+ let(:details) { reporter.details }
68
+
69
+ context 'the build details hash it returns' do
70
+
71
+ it 'reports the git branch' do
72
+ expect(details['branch']).to eq "#{git_repo.current_branch}"
73
+ end
74
+
75
+ it 'reports the git revision' do
76
+ expect(details['revision']).to eq "#{git_repo.log.first}"
77
+ end
78
+
79
+ it 'reports the build time' do
80
+ expect(details['build_time']).to eq "#{Time.now}"
81
+ end
82
+
83
+ it 'reports the app version' do
84
+ expect(details['version']).to eq "#{app.version}"
85
+ end
86
+
87
+ context 'when there is a custom details extension' do
88
+ before do
89
+ allow(reporter).to receive(:details_extension).and_return 'foo' => 'bar'
90
+ end
91
+
92
+ it 'includes the additional details in the hash it returns' do
93
+ expect(details['foo']).to eq 'bar'
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ describe '#details_extension' do
100
+
101
+ context 'when there is no ".build_reporter.yml" file in the root of the project' do
102
+
103
+ it 'returns an empty hash' do
104
+ expect(reporter.details_extension).to eq({})
105
+ end
106
+ end
107
+
108
+ context 'when there is a ".build_reporter.yml" file in the root of the project' do
109
+
110
+ it 'returns a hash representation of its YAML' do
111
+ allow(reporter).to receive(:details_extension_exist?).and_return true
112
+ allow(File).to receive(:read).with("#{app.root}/.build_reporter.yml").and_return "---\nsome_key: 'some value'\n"
113
+
114
+ expect(reporter.details_extension).to eq('some_key' => 'some value')
115
+ end
116
+ end
117
+ end
118
+
119
+ describe '#details_extension_exist?' do
120
+
121
+ context 'when there is no ".build_reporter.yml" in the project root' do
122
+
123
+ it 'returns false' do
124
+ expect(reporter.details_extension_exist?).to eq false
125
+ end
126
+ end
127
+
128
+ context 'when there is a ".build_reporter.yml" in the project root' do
129
+
130
+ it 'returns true' do
131
+ allow(File).to receive(:exist?).with(reporter.reporter_extension_file_path).and_return true
132
+
133
+ expect(reporter.details_extension_exist?).to eq true
134
+ end
135
+ end
136
+ end
137
+
138
+ describe '#build_time' do
139
+
140
+ it 'reports the current time' do
141
+ expect(reporter.build_time.strftime('%Y-%m-%d %H:%M')).to eq Time.now.strftime('%Y-%m-%d %H:%M')
142
+ end
143
+
144
+ context 'when build time is already set' do
145
+ it 'returns the existing value' do
146
+ reporter.instance_variable_set('@build_time', 'foo')
147
+
148
+ expect(reporter.build_time).to eq 'foo'
149
+ end
150
+ end
151
+ end
152
+
153
+ describe '#repo' do
154
+
155
+ it 'is a shortcut to app#repo' do
156
+ expect(reporter.repo).to eq app.repo
157
+ end
158
+ end
159
+
160
+ describe '#serialize' do
161
+
162
+ before do
163
+ allow(reporter).to receive(:details).and_return fake_details
164
+ end
165
+
166
+ context 'when it is passed "json"' do
167
+
168
+ let(:json) { JSON.parse(reporter.serialize('json')) }
169
+
170
+ it 'returns the build details as a JSON object' do
171
+ expect(json['foo']).to eq 'bar'
172
+ end
173
+ end
174
+
175
+ context 'when it is passed "yaml"' do
176
+
177
+ let(:yaml) { YAML.load(reporter.serialize('yaml')) }
178
+
179
+ it 'returns the build details as a JSON object' do
180
+ expect(yaml['foo']).to eq 'bar'
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,35 @@
1
+ require 'bundler/setup'
2
+ require 'git'
3
+
4
+ Bundler.require(:development)
5
+
6
+ Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f| require f }
7
+
8
+ SimpleCov.start
9
+
10
+ require 'middleman-build-reporter'
11
+ require 'middleman-build-reporter/extension'
12
+
13
+ def middleman_app(fixture_path)
14
+ root_dir = File.expand_path("../../fixtures/#{fixture_path}", __FILE__)
15
+
16
+ if File.exist?(File.join(root_dir, 'source'))
17
+ ENV['MM_SOURCE'] = 'source'
18
+ else
19
+ ENV['MM_SOURCE'] = ''
20
+ end
21
+
22
+ initialize_commands = @initialize_commands || []
23
+
24
+ initialize_commands.unshift lambda {
25
+ set :root, root_dir
26
+ set :environment, :development
27
+ set :show_exceptions, false
28
+ }
29
+
30
+ Middleman::Application.server.inst do
31
+ initialize_commands.each do |p|
32
+ instance_exec(&p)
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,248 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-build-reporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Ball
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: git
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: timecop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: cucumber
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: aruba
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fivemat
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Report build time details within your Middleman build
140
+ email:
141
+ - mikedball@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - Gemfile
149
+ - README.md
150
+ - Rakefile
151
+ - features/build_reporter.feature
152
+ - features/custom_build_reporter_file_name.feature
153
+ - features/extended_build_reporter.feature
154
+ - features/json_build_reporter.feature
155
+ - features/no_explicit_version.feature
156
+ - features/step_definitions/git_steps.rb
157
+ - features/step_definitions/json_reporter_file_steps.rb
158
+ - features/step_definitions/version_steps.rb
159
+ - features/support/env.rb
160
+ - features/support/helpers.rb
161
+ - fixtures/basic-app/config.rb
162
+ - fixtures/basic-app/source/images/background.png
163
+ - fixtures/basic-app/source/images/middleman.png
164
+ - fixtures/basic-app/source/index.html.erb
165
+ - fixtures/basic-app/source/javascripts/all.js
166
+ - fixtures/basic-app/source/layouts/layout.erb
167
+ - fixtures/basic-app/source/stylesheets/all.css
168
+ - fixtures/basic-app/source/stylesheets/normalize.css
169
+ - fixtures/custom-reporter-file-name/config.rb
170
+ - fixtures/custom-reporter-file-name/source/images/background.png
171
+ - fixtures/custom-reporter-file-name/source/images/middleman.png
172
+ - fixtures/custom-reporter-file-name/source/index.html.erb
173
+ - fixtures/custom-reporter-file-name/source/javascripts/all.js
174
+ - fixtures/custom-reporter-file-name/source/layouts/layout.erb
175
+ - fixtures/custom-reporter-file-name/source/stylesheets/all.css
176
+ - fixtures/custom-reporter-file-name/source/stylesheets/normalize.css
177
+ - fixtures/extended-build-reporter/.build_reporter.yml
178
+ - fixtures/extended-build-reporter/config.rb
179
+ - fixtures/extended-build-reporter/source/images/background.png
180
+ - fixtures/extended-build-reporter/source/images/middleman.png
181
+ - fixtures/extended-build-reporter/source/index.html.erb
182
+ - fixtures/extended-build-reporter/source/javascripts/all.js
183
+ - fixtures/extended-build-reporter/source/layouts/layout.erb
184
+ - fixtures/extended-build-reporter/source/stylesheets/all.css
185
+ - fixtures/extended-build-reporter/source/stylesheets/normalize.css
186
+ - fixtures/json-reporter-file/config.rb
187
+ - fixtures/json-reporter-file/source/images/background.png
188
+ - fixtures/json-reporter-file/source/images/middleman.png
189
+ - fixtures/json-reporter-file/source/index.html.erb
190
+ - fixtures/json-reporter-file/source/javascripts/all.js
191
+ - fixtures/json-reporter-file/source/layouts/layout.erb
192
+ - fixtures/json-reporter-file/source/stylesheets/all.css
193
+ - fixtures/json-reporter-file/source/stylesheets/normalize.css
194
+ - fixtures/no-version/config.rb
195
+ - fixtures/no-version/source/images/background.png
196
+ - fixtures/no-version/source/images/middleman.png
197
+ - fixtures/no-version/source/index.html.erb
198
+ - fixtures/no-version/source/javascripts/all.js
199
+ - fixtures/no-version/source/layouts/layout.erb
200
+ - fixtures/no-version/source/stylesheets/all.css
201
+ - fixtures/no-version/source/stylesheets/normalize.css
202
+ - lib/middleman-build-reporter.rb
203
+ - lib/middleman-build-reporter/extension.rb
204
+ - lib/middleman-build-reporter/reporter.rb
205
+ - lib/middleman-build-reporter/version.rb
206
+ - lib/middleman_extension.rb
207
+ - middleman-build-reporter.gemspec
208
+ - spec/middleman-build-reporter/extension_spec.rb
209
+ - spec/middleman-build-reporter/reporter_spec.rb
210
+ - spec/spec_helper.rb
211
+ homepage: https://github.com/mdb/middleman-build-reporter
212
+ licenses: []
213
+ metadata: {}
214
+ post_install_message:
215
+ rdoc_options: []
216
+ require_paths:
217
+ - lib
218
+ required_ruby_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ required_rubygems_version: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ requirements: []
229
+ rubyforge_project:
230
+ rubygems_version: 2.2.2
231
+ signing_key:
232
+ specification_version: 4
233
+ summary: Report build time details within your Middleman build
234
+ test_files:
235
+ - features/build_reporter.feature
236
+ - features/custom_build_reporter_file_name.feature
237
+ - features/extended_build_reporter.feature
238
+ - features/json_build_reporter.feature
239
+ - features/no_explicit_version.feature
240
+ - features/step_definitions/git_steps.rb
241
+ - features/step_definitions/json_reporter_file_steps.rb
242
+ - features/step_definitions/version_steps.rb
243
+ - features/support/env.rb
244
+ - features/support/helpers.rb
245
+ - spec/middleman-build-reporter/extension_spec.rb
246
+ - spec/middleman-build-reporter/reporter_spec.rb
247
+ - spec/spec_helper.rb
248
+ has_rdoc: