jasmine_junitxml_formatter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b6456b32d0f79ef1c46a0729cf97e91aa6a72fbe
4
+ data.tar.gz: 7b1cc46c50921b59b136758be96198d760f19c07
5
+ SHA512:
6
+ metadata.gz: 3fb57069d004992cb4779befdcbecacc1acbd6043597093d70901c9fbbc6ed251a3c6ad7893835415f72be5a640d85180c32486b0350e4e60dfc0bdc49adbf73
7
+ data.tar.gz: ac9588ef857f5c42edf11dbb85660bab5a4d142f66e490b4fc38975ba2422ffc5459306b86fde896c7ff2a9971e1de99f7430dca6719d639e86dd21e553566ef
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'jasmine', :git => 'https://github.com/pivotal/jasmine-gem.git'
6
+ # gem 'jasmine', :path => '../jasmine-gem'
7
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Pivotal Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Jasmine JUnit Xml Formatter [![Build Status](https://travis-ci.org/jasmine/jasmine_junitxml_formatter.png?branch=master)](https://travis-ci.org/jasmine/jasmine_junitxml_formatter)
2
+
3
+ Format jasmine results as junit compatible XML so CI servers, like Hudson/Jenkins can parse it
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jasmine_junitxml_formatter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install jasmine_junitxml_formatter
18
+
19
+ ## Usage
20
+
21
+ - In rails, simply `run rake jasmine:ci`, tests should generate a JUnit XML file
22
+ - Outside of rails, you may need to add `require 'jasmine_junitxml_formatter'` to your Rakefile after jasmine is required.
23
+
24
+ ### Configuring the output location:
25
+
26
+ Create a jasmine_junitxml_formatter.yml in spec/javascripts/support with something like this:
27
+
28
+ ---
29
+ junit_xml_path: /absolute/path/to/output
30
+
31
+ The config file will be processed with ERB if you want to make the destination dynamic. e.g.
32
+
33
+ ---
34
+ junit_xml_path: <%= File.join(Dir.pwd, 'some', 'relative', 'path')
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run all specs in spec directory (excluding plugin specs)"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jasmine_junitxml_formatter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jasmine_junitxml_formatter"
8
+ spec.version = JasmineJunitxmlFormatter::VERSION
9
+ spec.authors = ["Gregg Van Hove"]
10
+ spec.email = ["pair+gvanhove@pivotallabs.com"]
11
+ spec.description = %q{Format jasmine results as junit compatible XML so CI servers, like Hudson/Jenkins can parse it}
12
+ spec.summary = %q{Format jasmine results as junit compatible XML so CI servers, like Hudson/Jenkins can parse it}
13
+ spec.homepage = "https://github.com/jasmine/jasmine_junitxml_formatter"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency 'rspec'
23
+ spec.add_development_dependency "rake"
24
+
25
+ spec.add_dependency 'jasmine', '~> 2.0.0.alpha'
26
+ spec.add_dependency "nokogiri"
27
+ end
@@ -0,0 +1,59 @@
1
+ require 'nokogiri'
2
+
3
+ module Jasmine
4
+ module Formatters
5
+ class JunitXml
6
+ def initialize
7
+ load_config
8
+ @doc = Nokogiri::XML '<testsuites></testsuites>', nil, 'UTF-8'
9
+ end
10
+
11
+ def format(results)
12
+ testsuites = doc.at_css('testsuites')
13
+
14
+ results.each do |result|
15
+ testsuite = Nokogiri::XML::Node.new 'testsuite', doc
16
+ testsuite['tests'] = 1
17
+ testsuite['failures'] = result.failed? ? 1 : 0
18
+ testsuite['errors'] = 0
19
+ testsuite['name'] = result.suite_name
20
+ testsuite.parent = testsuites
21
+
22
+ testcase = Nokogiri::XML::Node.new 'testcase', doc
23
+ testcase['name'] = result.description
24
+
25
+ if result.failed?
26
+ result.failed_expectations.each do |failed_exp|
27
+ failure = Nokogiri::XML::Node.new 'failure', doc
28
+ failure['message'] = failed_exp.message
29
+ failure['type'] = 'Failure'
30
+ failure.content = failed_exp.stack
31
+ failure.parent = testcase
32
+ end
33
+ end
34
+
35
+ testcase.parent = testsuite
36
+ end
37
+ end
38
+
39
+ def done
40
+ File.open(File.join(output_dir, 'junit_results.xml'), 'w') do |file|
41
+ file.puts doc.to_xml(indent: 2)
42
+ end
43
+ end
44
+
45
+ private
46
+ attr_reader :doc, :config
47
+
48
+ def output_dir
49
+ config['junit_xml_path'] || Dir.pwd
50
+ end
51
+
52
+ def load_config
53
+ filepath = File.join(Dir.pwd, 'spec', 'javascripts', 'support', 'jasmine_junitxml_formatter.yml')
54
+ @config = YAML::load(ERB.new(File.read(filepath)).result(binding)) if File.exist?(filepath)
55
+ @config ||= {}
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,16 @@
1
+ def safe_gem_check(gem_name, version_string)
2
+ if Gem::Specification.respond_to?(:find_by_name)
3
+ Gem::Specification.find_by_name(gem_name, version_string)
4
+ elsif Gem.respond_to?(:available?)
5
+ Gem.available?(gem_name, version_string)
6
+ end
7
+ rescue Gem::LoadError
8
+ false
9
+ end
10
+
11
+ if safe_gem_check('rails', '>= 3')
12
+ require File.join('jasmine_junitxml_formatter', 'railtie')
13
+ else
14
+ require File.join('jasmine_junitxml_formatter', 'configure_jasmine.rb')
15
+ end
16
+
@@ -0,0 +1,6 @@
1
+ require 'jasmine'
2
+ require 'jasmine/formatters/junit_xml'
3
+
4
+ Jasmine.configure do |config|
5
+ config.formatters << Jasmine::Formatters::JunitXml
6
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails/railtie'
2
+
3
+ module JasmineJunitxmlFormatter
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load 'jasmine_junitxml_formatter/tasks/jasmine_junitxml_formatter.rake'
7
+ end
8
+ end
9
+ end
10
+
11
+
@@ -0,0 +1,8 @@
1
+ namespace :jasmine_junitxml_formatter do
2
+ task :setup do
3
+ require File.join('jasmine_junitxml_formatter', 'configure_jasmine')
4
+ end
5
+ end
6
+
7
+ task 'jasmine:require' => ['jasmine_junitxml_formatter:setup']
8
+
@@ -0,0 +1,3 @@
1
+ module JasmineJunitxmlFormatter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+ require 'nokogiri'
3
+
4
+ describe Jasmine::Formatters::JunitXml do
5
+
6
+ class FakeFile
7
+ def initialize
8
+ @content = ''
9
+ end
10
+
11
+ attr_reader :content
12
+
13
+ def puts(content)
14
+ @content << content
15
+ end
16
+ end
17
+
18
+ let(:file_stub) { FakeFile.new }
19
+
20
+ describe 'creating the xml' do
21
+ before do
22
+ Dir.stub(:pwd).and_return('/junit_path')
23
+ File.stub(:open).and_call_original
24
+ File.stub(:open).with('/junit_path/junit_results.xml', 'w').and_yield(file_stub)
25
+ end
26
+
27
+ describe 'when the full suite passes' do
28
+ it 'shows the spec counts' do
29
+ results = [passing_result('fullName' => 'Passing test', 'description' => 'test')]
30
+ subject = Jasmine::Formatters::JunitXml.new
31
+
32
+ subject.format(results)
33
+ subject.done
34
+ xml = Nokogiri::XML(file_stub.content)
35
+
36
+ testsuite = xml.xpath('/testsuites/testsuite').first
37
+ testsuite['tests'].should == '1'
38
+ testsuite['failures'].should == '0'
39
+ testsuite['name'].should == 'Passing'
40
+
41
+ xml.xpath('//testcase').size.should == 1
42
+ xml.xpath('//testcase').first['name'].should == 'test'
43
+ end
44
+ end
45
+
46
+ describe 'when there are failures' do
47
+ it 'shows the spec counts' do
48
+ results1 = [passing_result]
49
+ results2 = [failing_result]
50
+ subject = Jasmine::Formatters::JunitXml.new
51
+
52
+ subject.format(results1)
53
+ subject.format(results2)
54
+ subject.done
55
+ xml = Nokogiri::XML(file_stub.content)
56
+
57
+ testsuite = xml.xpath('/testsuites/testsuite').first
58
+ testsuite['tests'].should == '1'
59
+ testsuite['failures'].should == '0'
60
+
61
+ testsuite = xml.xpath('/testsuites/testsuite')[1]
62
+ testsuite['tests'].should == '1'
63
+ testsuite['failures'].should == '1'
64
+
65
+ xml.xpath('//testcase').size.should == 2
66
+ xml.xpath('//testcase/failure').size.should == 1
67
+ xml.xpath('//testcase/failure').first['message'].should == 'a failure message'
68
+ xml.xpath('//testcase/failure').first.content.should == 'a stack trace'
69
+ end
70
+ end
71
+ end
72
+
73
+ describe 'when the output directory has been customized' do
74
+ before do
75
+ Dir.stub(:pwd).and_return('/default_path')
76
+ config_path = File.join('/default_path', 'spec', 'javascripts', 'support', 'jasmine_junitxml_formatter.yml')
77
+ File.stub(:exist?).with(config_path).and_return(true)
78
+ File.stub(:read).with(config_path).and_return <<-YAML
79
+ ---
80
+ junit_xml_path: "/custom_path"
81
+ YAML
82
+ File.stub(:open).and_call_original
83
+ File.stub(:open).with('/custom_path/junit_results.xml', 'w').and_yield(file_stub)
84
+ end
85
+
86
+ it 'writes to the specified location' do
87
+ results = [passing_result('fullName' => 'Passing test', 'description' => 'test')]
88
+ subject = Jasmine::Formatters::JunitXml.new
89
+
90
+ subject.format(results)
91
+ subject.done
92
+ file_stub.content.should_not == ''
93
+ end
94
+ end
95
+
96
+ def failing_result(options = {})
97
+ Jasmine::Result.new(failing_raw_result.merge(options))
98
+ end
99
+
100
+ def passing_result(options = {})
101
+ Jasmine::Result.new(passing_raw_result.merge(options))
102
+ end
103
+ end
@@ -0,0 +1,38 @@
1
+ require 'rspec'
2
+ require 'jasmine_junitxml_formatter'
3
+
4
+ def in_temp_dir
5
+ project_root = File.expand_path(File.join('..', '..'), __FILE__)
6
+ Dir.mktmpdir do |tmp_dir|
7
+ begin
8
+ Dir.chdir tmp_dir
9
+ yield tmp_dir, project_root
10
+ ensure
11
+ Dir.chdir project_root
12
+ end
13
+ end
14
+ end
15
+
16
+ def passing_raw_result
17
+ {'id' => 123, 'status' => 'passed', 'fullName' => 'Passing test', 'description' => 'Passing', 'failedExpectations' => []}
18
+ end
19
+
20
+ def pending_raw_result
21
+ {'id' => 123, 'status' => 'pending', 'fullName' => 'Passing test', 'description' => 'Pending', 'failedExpectations' => []}
22
+ end
23
+
24
+ def failing_raw_result
25
+ {
26
+ 'status' => 'failed',
27
+ 'id' => 124,
28
+ 'description' => 'a failing spec',
29
+ 'fullName' => 'a suite with a failing spec',
30
+ 'failedExpectations' => [
31
+ {
32
+ 'message' => 'a failure message',
33
+ 'stack' => 'a stack trace'
34
+ }
35
+ ]
36
+ }
37
+ end
38
+
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jasmine_junitxml_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gregg Van Hove
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rake
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: jasmine
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0.alpha
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.0.alpha
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Format jasmine results as junit compatible XML so CI servers, like Hudson/Jenkins
84
+ can parse it
85
+ email:
86
+ - pair+gvanhove@pivotallabs.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - jasmine_junitxml_formatter.gemspec
97
+ - lib/jasmine/formatters/junit_xml.rb
98
+ - lib/jasmine_junitxml_formatter.rb
99
+ - lib/jasmine_junitxml_formatter/configure_jasmine.rb
100
+ - lib/jasmine_junitxml_formatter/railtie.rb
101
+ - lib/jasmine_junitxml_formatter/tasks/jasmine_junitxml_formatter.rake
102
+ - lib/jasmine_junitxml_formatter/version.rb
103
+ - spec/lib/jasmine/formatters/junit_xml_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: https://github.com/jasmine/jasmine_junitxml_formatter
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.0.5
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Format jasmine results as junit compatible XML so CI servers, like Hudson/Jenkins
129
+ can parse it
130
+ test_files:
131
+ - spec/lib/jasmine/formatters/junit_xml_spec.rb
132
+ - spec/spec_helper.rb