shouldit-formatters-rspec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad79f17f3eea5fba84f42361f962561d9a6b084d
4
+ data.tar.gz: 7cb8b55308ac7eba75d4d82567abef73cbfddc7a
5
+ SHA512:
6
+ metadata.gz: 52c83e51b4627617220c3ff79c279f74d05842a8b6d9da00445e3de27aff34938276ce6ac9b5a947445f7504b02477630738a67052fd1213b969e4a0d8ad8093
7
+ data.tar.gz: a024aa3504cc2c146f857c5601351d90de1cf5b8bb798fc7a4ddc4896cf3969fb6334f9393011e8f09e33e6f03ac87ceda61399aacc1457bc2da95a1ffde9df9
@@ -0,0 +1 @@
1
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org' do
2
+ gemspec
3
+ end
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shouldit-formatters-rspec (0.0.1)
5
+ rspec-core (~> 3.2)
6
+ rspec-expectations (~> 3.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.2.5)
12
+ rake (10.4.2)
13
+ rspec-core (3.3.0)
14
+ rspec-support (~> 3.3.0)
15
+ rspec-expectations (3.3.0)
16
+ diff-lcs (>= 1.2.0, < 2.0)
17
+ rspec-support (~> 3.3.0)
18
+ rspec-support (3.3.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ rake (~> 10.4)
25
+ shouldit-formatters-rspec!
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2013-2014 British Broadcasting Corporation. http://www.bbc.co.uk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # ShouldIT RSpec Formatter
2
+
3
+ Formats RSpec output as ShouldIT compatible JSON. Compatible with RSpec 3.2+
4
+
5
+ ## Usage
6
+
7
+ Add `shouldit-formatter-rspec` to your Gemfile
8
+
9
+ gem 'shouldit-formatters-rspec'
10
+
11
+ Configure RSpec to write results to a file
12
+
13
+ require 'shouldit/formatters'
14
+
15
+ RSpec.configure do |config|
16
+ config.output_stream = File.open('spec/results.json', 'w')
17
+ config.formatter = ShouldIT::Formatters::RSpecFormatter
18
+ end
19
+
20
+ Configure ShouldIT to watch for changes in `shouldit.conf.json`
21
+
22
+ {
23
+ "results": "spec/results.json"
24
+ }
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'rspec/core/rake_task'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1 @@
1
+ require_relative 'shouldit/formatters'
@@ -0,0 +1 @@
1
+ require_relative 'formatters/rspec_formatter'
@@ -0,0 +1,60 @@
1
+ require 'rspec/core'
2
+ require 'rspec/core/formatters/base_formatter'
3
+ require 'json'
4
+
5
+ module ShouldIT
6
+ module Formatters
7
+ class RSpecFormatter < ::RSpec::Core::Formatters::BaseFormatter
8
+ VERSION = '0.0.1'
9
+
10
+ ::RSpec::Core::Formatters.register self, :stop, :close
11
+
12
+ attr_reader :output, :specs
13
+
14
+ def initialize(output)
15
+ super
16
+
17
+ @specs = {}
18
+ end
19
+
20
+ def stop(notification)
21
+ examples = notification.examples.map do |example|
22
+ map_example(example)
23
+ end
24
+
25
+ build_output(examples)
26
+ end
27
+
28
+ def map_example(example)
29
+ {
30
+ group: group_for(example.metadata),
31
+ description: example.metadata[:description],
32
+ result: result_for(example.metadata)
33
+ }
34
+ end
35
+
36
+ def group_for(metadata)
37
+ metadata[:full_description].gsub(metadata[:description], '').strip
38
+ end
39
+
40
+ def result_for(metadata)
41
+ metadata[:execution_result].status.upcase.to_s
42
+ end
43
+
44
+ def build_output(examples)
45
+ examples.each do |example|
46
+ group = @specs[example[:group]] || {}
47
+
48
+ @specs[example[:group]] = group.merge({
49
+ example[:description] => example[:result]
50
+ })
51
+ end
52
+ end
53
+
54
+ def close(_notification)
55
+ output.write @specs.to_json
56
+ output.close if IO === output && output != $stdout
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+
3
+ require 'shouldit'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'shouldit-formatters-rspec'
7
+ s.version = ShouldIT::Formatters::RSpecFormatter::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Richard McIntyre', 'Luke Barratt']
10
+ s.license = 'MIT'
11
+ s.homepage = 'https://github.com/should-it/shouldit-formatters-rspec'
12
+ s.summary = 'ShouldIT RSpec Formatter'
13
+ s.description = 'Formats RSpec output as ShouldIT compatible JSON'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- spec/*`.split("\n")
17
+ s.require_paths = ['lib']
18
+
19
+ s.add_runtime_dependency 'rspec-core', '~> 3.2'
20
+ s.add_runtime_dependency 'rspec-expectations', '~> 3.2'
21
+
22
+ s.add_development_dependency 'rake', '~> 10.4'
23
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+ require 'support/formatter_support'
3
+ require 'shouldit'
4
+
5
+ RSpec.describe ShouldIT::Formatters::RSpecFormatter do
6
+ include FormatterSupport
7
+
8
+ let(:group_description) { 'ShouldIT Example Group' }
9
+
10
+ let(:example_group) do
11
+ RSpec.describe group_description do
12
+ it 'Pass' do
13
+ expect(true).to eq(true)
14
+ end
15
+
16
+ it 'Fail' do
17
+ fail
18
+ end
19
+
20
+ it 'Pending'
21
+
22
+ context 'Nested' do
23
+ it 'Pass' do
24
+ expect(false).to eq(false)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ before do
31
+ reporter.report(example_group.examples.size) do |runner|
32
+ example_group.run(runner)
33
+ end
34
+ end
35
+
36
+ it 'Renders as JSON' do
37
+ expect(JSON.parse(formatter_output.string)).to be_truthy
38
+ end
39
+
40
+ it 'Groups tests by descriptions' do
41
+ expect(formatter.specs).to have_key(group_description)
42
+ end
43
+
44
+ it 'Groups tests by nested contexts' do
45
+ expect(formatter.specs).to have_key("#{group_description} Nested")
46
+ end
47
+
48
+ it 'Contains the description and corresponding result' do
49
+ group_output = formatter.specs[group_description]
50
+
51
+ example_map = {
52
+ 'Pass' => 'PASSED',
53
+ 'Fail' => 'FAILED',
54
+ 'Pending' => 'PENDING'
55
+ }
56
+
57
+ example_map.each do |description, result|
58
+ expect(group_output[description]).to eq(result)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec/core'
2
+
3
+ RSpec.configure do |config|
4
+ config.color = true
5
+ config.order = :random
6
+ config.formatter = :documentation
7
+ end
@@ -0,0 +1,35 @@
1
+ module FormatterSupport
2
+ def reporter
3
+ @reporter ||= setup_reporter
4
+ end
5
+
6
+ def config
7
+ @configuration ||= begin
8
+ RSpec::Core::Configuration.new.tap do |config|
9
+ config.output_stream = formatter_output
10
+ end
11
+ end
12
+ end
13
+
14
+ def formatter
15
+ @formatter ||= begin
16
+ setup_reporter
17
+ @formatter
18
+ end
19
+ end
20
+
21
+ def setup_reporter
22
+ config.add_formatter described_class
23
+ @formatter = config.formatters.first
24
+ @reporter = config.reporter
25
+ end
26
+
27
+ def setup_profiler
28
+ config.profile_examples = true
29
+ reporter.setup_profiler
30
+ end
31
+
32
+ def formatter_output
33
+ @formatter_output ||= StringIO.new
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shouldit-formatters-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard McIntyre
8
+ - Luke Barratt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec-expectations
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.2'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.2'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.4'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.4'
56
+ description: Formats RSpec output as ShouldIT compatible JSON
57
+ email:
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - lib/shouldit.rb
69
+ - lib/shouldit/formatters.rb
70
+ - lib/shouldit/formatters/rspec_formatter.rb
71
+ - shouldit-formatters-rspec.gemspec
72
+ - spec/lib/rspec/json_formatter_spec.rb
73
+ - spec/spec_helper.rb
74
+ - spec/support/formatter_support.rb
75
+ homepage: https://github.com/should-it/shouldit-formatters-rspec
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: ShouldIT RSpec Formatter
99
+ test_files:
100
+ - spec/lib/rspec/json_formatter_spec.rb
101
+ - spec/spec_helper.rb
102
+ - spec/support/formatter_support.rb