jasmine_junitxml_formatter 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6456b32d0f79ef1c46a0729cf97e91aa6a72fbe
4
- data.tar.gz: 7b1cc46c50921b59b136758be96198d760f19c07
3
+ metadata.gz: 74ea953e808ffa3eaf7adc0e8fd7e4ad872a6f48
4
+ data.tar.gz: ec49d74c850a98ddac1784422a846e2c9a95f306
5
5
  SHA512:
6
- metadata.gz: 3fb57069d004992cb4779befdcbecacc1acbd6043597093d70901c9fbbc6ed251a3c6ad7893835415f72be5a640d85180c32486b0350e4e60dfc0bdc49adbf73
7
- data.tar.gz: ac9588ef857f5c42edf11dbb85660bab5a4d142f66e490b4fc38975ba2422ffc5459306b86fde896c7ff2a9971e1de99f7430dca6719d639e86dd21e553566ef
6
+ metadata.gz: ab473edbef2b69ca95e6d6613be1ce3cacd6b81bcf5331cbcf7e1093ff184dabb0d86d1e5bdded8ebcde8fafbf5237638635bce951436a62f871328c98fc8807
7
+ data.tar.gz: 541198a2fc2ebf1543b8113be98703542e187267726fa800a170679ca02fa619e5cea2b188efafe9c6eb5fe1a2c41e72f58b75c68ed4822058b3bbbc2b97b6d6
@@ -4,7 +4,7 @@ module Jasmine
4
4
  module Formatters
5
5
  class JunitXml
6
6
  def initialize
7
- load_config
7
+ load_config ENV['JASMINE_JUNIT_XML_CONFIG_PATH']
8
8
  @doc = Nokogiri::XML '<testsuites></testsuites>', nil, 'UTF-8'
9
9
  end
10
10
 
@@ -37,6 +37,7 @@ module Jasmine
37
37
  end
38
38
 
39
39
  def done
40
+ FileUtils.mkdir_p(output_dir)
40
41
  File.open(File.join(output_dir, 'junit_results.xml'), 'w') do |file|
41
42
  file.puts doc.to_xml(indent: 2)
42
43
  end
@@ -49,8 +50,8 @@ module Jasmine
49
50
  config['junit_xml_path'] || Dir.pwd
50
51
  end
51
52
 
52
- def load_config
53
- filepath = File.join(Dir.pwd, 'spec', 'javascripts', 'support', 'jasmine_junitxml_formatter.yml')
53
+ def load_config(filepath=nil)
54
+ filepath ||= File.join(Dir.pwd, 'spec', 'javascripts', 'support', 'jasmine_junitxml_formatter.yml')
54
55
  @config = YAML::load(ERB.new(File.read(filepath)).result(binding)) if File.exist?(filepath)
55
56
  @config ||= {}
56
57
  end
@@ -1,3 +1,3 @@
1
1
  module JasmineJunitxmlFormatter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -17,11 +17,15 @@ describe Jasmine::Formatters::JunitXml do
17
17
 
18
18
  let(:file_stub) { FakeFile.new }
19
19
 
20
+ before do
21
+ allow(FileUtils).to receive(:mkdir_p)
22
+ end
23
+
20
24
  describe 'creating the xml' do
21
25
  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)
26
+ allow(Dir).to receive(:pwd).and_return('/junit_path')
27
+ allow(File).to receive(:open).and_call_original
28
+ allow(File).to receive(:open).with('/junit_path/junit_results.xml', 'w').and_yield(file_stub)
25
29
  end
26
30
 
27
31
  describe 'when the full suite passes' do
@@ -34,12 +38,12 @@ describe Jasmine::Formatters::JunitXml do
34
38
  xml = Nokogiri::XML(file_stub.content)
35
39
 
36
40
  testsuite = xml.xpath('/testsuites/testsuite').first
37
- testsuite['tests'].should == '1'
38
- testsuite['failures'].should == '0'
39
- testsuite['name'].should == 'Passing'
41
+ expect(testsuite['tests']).to eq '1'
42
+ expect(testsuite['failures']).to eq '0'
43
+ expect(testsuite['name']).to eq 'Passing'
40
44
 
41
- xml.xpath('//testcase').size.should == 1
42
- xml.xpath('//testcase').first['name'].should == 'test'
45
+ expect(xml.xpath('//testcase').size).to eq 1
46
+ expect(xml.xpath('//testcase').first['name']).to eq 'test'
43
47
  end
44
48
  end
45
49
 
@@ -55,32 +59,32 @@ describe Jasmine::Formatters::JunitXml do
55
59
  xml = Nokogiri::XML(file_stub.content)
56
60
 
57
61
  testsuite = xml.xpath('/testsuites/testsuite').first
58
- testsuite['tests'].should == '1'
59
- testsuite['failures'].should == '0'
62
+ expect(testsuite['tests']).to eq '1'
63
+ expect(testsuite['failures']).to eq '0'
60
64
 
61
65
  testsuite = xml.xpath('/testsuites/testsuite')[1]
62
- testsuite['tests'].should == '1'
63
- testsuite['failures'].should == '1'
66
+ expect(testsuite['tests']).to eq '1'
67
+ expect(testsuite['failures']).to eq '1'
64
68
 
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
+ expect(xml.xpath('//testcase').size).to eq 2
70
+ expect(xml.xpath('//testcase/failure').size).to eq 1
71
+ expect(xml.xpath('//testcase/failure').first['message']).to eq 'a failure message'
72
+ expect(xml.xpath('//testcase/failure').first.content).to eq 'a stack trace'
69
73
  end
70
74
  end
71
75
  end
72
76
 
73
77
  describe 'when the output directory has been customized' do
74
78
  before do
75
- Dir.stub(:pwd).and_return('/default_path')
79
+ allow(Dir).to receive(:pwd).and_return('/default_path')
76
80
  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
81
+ allow(File).to receive(:exist?).with(config_path).and_return(true)
82
+ allow(File).to receive(:read).with(config_path).and_return <<-YAML
79
83
  ---
80
84
  junit_xml_path: "/custom_path"
81
85
  YAML
82
- File.stub(:open).and_call_original
83
- File.stub(:open).with('/custom_path/junit_results.xml', 'w').and_yield(file_stub)
86
+ allow(File).to receive(:open).and_call_original
87
+ allow(File).to receive(:open).with('/custom_path/junit_results.xml', 'w').and_yield(file_stub)
84
88
  end
85
89
 
86
90
  it 'writes to the specified location' do
@@ -89,7 +93,50 @@ YAML
89
93
 
90
94
  subject.format(results)
91
95
  subject.done
92
- file_stub.content.should_not == ''
96
+ expect(file_stub.content).to_not eq ''
97
+ end
98
+
99
+ it 'creates the directory if it does not exist' do
100
+ subject = Jasmine::Formatters::JunitXml.new
101
+
102
+ subject.format([])
103
+ expect(FileUtils).to receive(:mkdir_p).with('/custom_path')
104
+ subject.done
105
+ end
106
+ end
107
+
108
+ describe 'with a custom config file path' do
109
+ before do
110
+ allow(Dir).to receive(:pwd).and_return('/default_path')
111
+ config_path = File.join('/other_path', 'jasmine_junitxml_formatter.yml')
112
+ allow(File).to receive(:exist?).with(config_path).and_return(true)
113
+ allow(File).to receive(:read).with(config_path).and_return <<-YAML
114
+ ---
115
+ junit_xml_path: "/other_custom_path"
116
+ YAML
117
+ allow(File).to receive(:open).and_call_original
118
+ allow(File).to receive(:open).with('/other_custom_path/junit_results.xml', 'w').and_yield(file_stub)
119
+ end
120
+
121
+ subject do
122
+ ENV['JASMINE_JUNIT_XML_CONFIG_PATH'] = '/other_path/jasmine_junitxml_formatter.yml'
123
+ formatter = Jasmine::Formatters::JunitXml.new
124
+ ENV.delete 'JASMINE_JUNIT_XML_CONFIG_PATH'
125
+ formatter
126
+ end
127
+
128
+ it 'writes to the specified location' do
129
+ results = [passing_result('fullName' => 'Passing test', 'description' => 'test')]
130
+
131
+ subject.format(results)
132
+ subject.done
133
+ expect(file_stub.content).to_not eq ''
134
+ end
135
+
136
+ it 'creates the directory if it does not exist' do
137
+ subject.format([])
138
+ expect(FileUtils).to receive(:mkdir_p).with('/other_custom_path')
139
+ subject.done
93
140
  end
94
141
  end
95
142
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine_junitxml_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Van Hove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-27 00:00:00.000000000 Z
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 2.0.5
125
+ rubygems_version: 2.0.3
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: Format jasmine results as junit compatible XML so CI servers, like Hudson/Jenkins