jasmine-parser 0.0.1
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.
- data/.gitignore +1 -0
- data/Gemfile +37 -0
- data/LICENSE.txt +29 -0
- data/README.md +118 -0
- data/Rakefile +43 -0
- data/jasmine-parser.gemspec +50 -0
- data/lib/jasmine-parser/announcer.rb +55 -0
- data/lib/jasmine-parser/config.rb +57 -0
- data/lib/jasmine-parser/exceptions.rb +46 -0
- data/lib/jasmine-parser/file_parser.rb +62 -0
- data/lib/jasmine-parser/jasmine_suite.rb +69 -0
- data/lib/jasmine-parser/javascript_object_wrapper.rb +136 -0
- data/lib/jasmine-parser/location_finder.rb +100 -0
- data/lib/jasmine-parser/node_collector.rb +88 -0
- data/lib/jasmine-parser/node_factory.rb +121 -0
- data/lib/jasmine-parser/nodes/example_node.rb +40 -0
- data/lib/jasmine-parser/nodes/function_invocation_node.rb +70 -0
- data/lib/jasmine-parser/nodes/group_node.rb +40 -0
- data/lib/jasmine-parser/nodes/node.rb +120 -0
- data/lib/jasmine-parser/nodes/root_node.rb +40 -0
- data/lib/jasmine-parser/nodes/shared_behavior_decl_node.rb +54 -0
- data/lib/jasmine-parser/nodes/shared_behavior_invoc_node.rb +80 -0
- data/lib/jasmine-parser.rb +53 -0
- data/spec/end_to_end_suite_parser_spec.rb +100 -0
- data/spec/file_parser_spec.rb +68 -0
- data/spec/fixture/spec/call_to_shared_example_in_other_file_spec.js +38 -0
- data/spec/fixture/spec/empty_shared_examples_spec.js +21 -0
- data/spec/fixture/spec/example_spec.js +48 -0
- data/spec/fixture/spec/example_spec_with_strange_spacing.js +48 -0
- data/spec/fixture/spec/multi_declaration_shared_spec.js +26 -0
- data/spec/fixture/spec/not_properly_formatted.js +24 -0
- data/spec/fixture/spec/shared_examples_function_declaration_spec.js +49 -0
- data/spec/fixture/spec/shared_examples_spec.js +43 -0
- data/spec/fixture/spec/small_file.js +5 -0
- data/spec/location_finder_spec.rb +263 -0
- data/spec/node_cloning_spec.rb +123 -0
- data/spec/node_collector_spec.rb +87 -0
- data/spec/node_spec.rb +102 -0
- data/spec/shared_behavior_decl_node_spec.rb +59 -0
- data/spec/shared_behavior_invoc_node_spec.rb +129 -0
- data/spec/shared_examples_for_end_to_end.rb +239 -0
- data/spec/shared_examples_in_new_function_spec.rb +74 -0
- data/spec/shared_examples_spec.rb +71 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/suite_spec.rb +70 -0
- metadata +128 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
// Declare shared example in variable
|
2
|
+
|
3
|
+
var sharedBehaviorInMethod;
|
4
|
+
|
5
|
+
sharedBehaviorInMethod = function(some_var) {
|
6
|
+
describe("shared group in variable", function() {
|
7
|
+
return it("example 1", function() {
|
8
|
+
return expect(true).toBe(true);
|
9
|
+
});
|
10
|
+
});
|
11
|
+
};
|
12
|
+
|
13
|
+
window.sharedBehaviorOnWindow = {};
|
14
|
+
|
15
|
+
sharedBehaviorOnWindow.sharedExample = function(){
|
16
|
+
|
17
|
+
describe('shared group on window', function() {
|
18
|
+
it('example 2', function() {
|
19
|
+
return expect(true).toBe(true);
|
20
|
+
});
|
21
|
+
return it('example 3', function() {
|
22
|
+
return expect(true).toBe(true);
|
23
|
+
});
|
24
|
+
});
|
25
|
+
|
26
|
+
};
|
@@ -0,0 +1,24 @@
|
|
1
|
+
describe("example_spec", function() {
|
2
|
+
it("should be here for path loading tests", function() {
|
3
|
+
expect(true).toBe(true);
|
4
|
+
})
|
5
|
+
|
6
|
+
describe("nested_groups", function() {
|
7
|
+
it("should contain the full name of nested example", function(){
|
8
|
+
expect(true).toBe(true);
|
9
|
+
})
|
10
|
+
|
11
|
+
context('context group', function(){
|
12
|
+
describe('nested group in context', function(){
|
13
|
+
it("should be here for nested context", function(){
|
14
|
+
expect(true).toBe(true);
|
15
|
+
})
|
16
|
+
})
|
17
|
+
})
|
18
|
+
})
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
//no closing }) on line 10
|
@@ -0,0 +1,49 @@
|
|
1
|
+
describe("shared example declared in new function", function() {
|
2
|
+
|
3
|
+
|
4
|
+
describe("group 1", function() {
|
5
|
+
|
6
|
+
function sharedBehaviorInFunction(something) {
|
7
|
+
describe("(shared)", function() {
|
8
|
+
beforeEach(function() {
|
9
|
+
$('foo').remove();
|
10
|
+
});
|
11
|
+
|
12
|
+
it("example 1", function() {
|
13
|
+
expect(0).toEqual(0);
|
14
|
+
});
|
15
|
+
|
16
|
+
describe("group 1.1", function() {
|
17
|
+
|
18
|
+
it("example 2", function() {
|
19
|
+
expect(bar).toMatch(/^foo/);
|
20
|
+
});
|
21
|
+
});
|
22
|
+
});
|
23
|
+
}
|
24
|
+
|
25
|
+
function decoyFunctionOne(){
|
26
|
+
alert("decoy function, should be ignored");
|
27
|
+
}
|
28
|
+
|
29
|
+
describe("group 2", function() {
|
30
|
+
sharedBehaviorInFunction(something);
|
31
|
+
|
32
|
+
describe("source", function() {
|
33
|
+
it("example 3", function() {
|
34
|
+
expect(bar).toMatch('foo');
|
35
|
+
});
|
36
|
+
});
|
37
|
+
});
|
38
|
+
|
39
|
+
describe("group 3", function() {
|
40
|
+
it("example 4", function() {
|
41
|
+
expect($('foo').length).toEqual(0);
|
42
|
+
});
|
43
|
+
});
|
44
|
+
});
|
45
|
+
});
|
46
|
+
|
47
|
+
function decoyFunctionTwo(){
|
48
|
+
alert("decoy function, should be ignored");
|
49
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
describe("node containing shared example using a window.sharedExamplesFor", function(){
|
2
|
+
|
3
|
+
sharedExamplesFor("shared example on window", function() {
|
4
|
+
it("example 1", function() {
|
5
|
+
expect(true).toBe(true);
|
6
|
+
});
|
7
|
+
it("example 2", function() {
|
8
|
+
expect(true).toBe(true);
|
9
|
+
});
|
10
|
+
});
|
11
|
+
|
12
|
+
|
13
|
+
itBehavesLike('shared example on window');
|
14
|
+
|
15
|
+
})
|
16
|
+
|
17
|
+
|
18
|
+
describe('node calling a shared behavior that is in another node', function() {
|
19
|
+
|
20
|
+
describe("group that needs shared example", function() {
|
21
|
+
itBehavesLike('shared example on window');
|
22
|
+
|
23
|
+
describe("group that does not use shared example", function() {
|
24
|
+
it("test that does not use shared example", function() {
|
25
|
+
expect(true).toBe(true);
|
26
|
+
});
|
27
|
+
});
|
28
|
+
});
|
29
|
+
});
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
sharedExamplesFor("shared outside any group", function() {
|
34
|
+
it("example 3", function() {
|
35
|
+
expect(true).toBe(true);
|
36
|
+
});
|
37
|
+
it("example 4", function() {
|
38
|
+
expect(true).toBe(true);
|
39
|
+
});
|
40
|
+
});
|
41
|
+
|
42
|
+
|
43
|
+
|
@@ -0,0 +1,263 @@
|
|
1
|
+
# Copyright (c) 2013, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
require 'spec_helper'
|
32
|
+
|
33
|
+
|
34
|
+
describe JasmineParser::LocationFiner do
|
35
|
+
|
36
|
+
describe "Not shared examples" do
|
37
|
+
before(:each) do
|
38
|
+
@file = "spec/fixture/spec/example_spec.js"
|
39
|
+
@suite = JasmineParser::JasmineSuite.new
|
40
|
+
@parser = JasmineParser::FileParser.new(@suite)
|
41
|
+
@parser.parse [@file]
|
42
|
+
|
43
|
+
@location_finder = JasmineParser::LocationFiner.new @suite
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
@test_and_location = {
|
48
|
+
"example_spec should be here for path loading tests" => [
|
49
|
+
"#{@file}:2:in `should be here for path loading tests'", "#{@file}:1:in `example_spec'"
|
50
|
+
|
51
|
+
],
|
52
|
+
"example_spec nested_groups should contain the full name of nested example" => [
|
53
|
+
"#{@file}:7:in `should contain the full name of nested example'", "#{@file}:6:in `nested_groups'", "#{@file}:1:in `example_spec'"
|
54
|
+
],
|
55
|
+
"example_spec context group nested group in context should be here for nested context" => [
|
56
|
+
|
57
|
+
"#{@file}:14:in `should be here for nested context'", "#{@file}:13:in `nested group in context'", "#{@file}:12:in `context group'", "#{@file}:1:in `example_spec'"
|
58
|
+
],
|
59
|
+
|
60
|
+
"example with return return example_spec should have example name with return upfront" => [
|
61
|
+
"#{@file}:23:in `should have example name with return upfront'", "#{@file}:22:in `return example_spec'", "#{@file}:21:in `example with return'"
|
62
|
+
],
|
63
|
+
"example with return return example_spec return context group inside return context should be here for nested context with return" => [
|
64
|
+
"#{@file}:29:in `should be here for nested context with return'", "#{@file}:28:in `group inside return context'", "#{@file}:27:in `return context'", "#{@file}:22:in `return example_spec'", "#{@file}:21:in `example with return'"
|
65
|
+
],
|
66
|
+
|
67
|
+
"root context nested_group in context spec in context" => [
|
68
|
+
"#{@file}:39:in `spec in context'", "#{@file}:38:in `nested_group in context'", "#{@file}:37:in `root context'"
|
69
|
+
],
|
70
|
+
}
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should have 6 tests total" do
|
75
|
+
@location_finder.example_count.should == 6
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should have the correct name and line number for all examples" do
|
79
|
+
@test_and_location.keys.each do |test_name|
|
80
|
+
@location_finder.to_hash[test_name].should == @test_and_location[test_name]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
describe "Shared examples" do
|
89
|
+
|
90
|
+
context "shared in the same file" do
|
91
|
+
before(:each) do
|
92
|
+
@file = "spec/fixture/spec/shared_examples_spec.js"
|
93
|
+
@suite = JasmineParser::JasmineSuite.new
|
94
|
+
@parser = JasmineParser::FileParser.new(@suite)
|
95
|
+
@parser.parse [@file]
|
96
|
+
|
97
|
+
@location_finder = JasmineParser::LocationFiner.new @suite
|
98
|
+
|
99
|
+
file = "spec/fixture/spec/shared_examples_spec.js"
|
100
|
+
|
101
|
+
@test_and_location = {
|
102
|
+
"node containing shared example using a window.sharedExamplesFor example 1" => [
|
103
|
+
"#{file}:4:in `example 1'", "#{file}:13:in `shared example on window'", "#{file}:1:in `node containing shared example using a window.sharedExamplesFor'"
|
104
|
+
],
|
105
|
+
"node containing shared example using a window.sharedExamplesFor example 2" => [
|
106
|
+
"#{file}:7:in `example 2'", "#{file}:13:in `shared example on window'", "#{file}:1:in `node containing shared example using a window.sharedExamplesFor'"
|
107
|
+
],
|
108
|
+
|
109
|
+
"node calling a shared behavior that is in another node group that needs shared example example 1" => [
|
110
|
+
"#{file}:4:in `example 1'", "#{file}:21:in `shared example on window'", "#{file}:20:in `group that needs shared example'", "#{file}:18:in `node calling a shared behavior that is in another node'"
|
111
|
+
],
|
112
|
+
"node calling a shared behavior that is in another node group that needs shared example example 2" => [
|
113
|
+
"#{file}:7:in `example 2'", "#{file}:21:in `shared example on window'", "#{file}:20:in `group that needs shared example'", "#{file}:18:in `node calling a shared behavior that is in another node'"
|
114
|
+
],
|
115
|
+
|
116
|
+
"node calling a shared behavior that is in another node group that needs shared example group that does not use shared example test that does not use shared example" => [
|
117
|
+
"#{file}:24:in `test that does not use shared example'","#{file}:23:in `group that does not use shared example'", "#{file}:20:in `group that needs shared example'", "#{file}:18:in `node calling a shared behavior that is in another node'",
|
118
|
+
]
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should have 5 tests total" do
|
123
|
+
@location_finder.example_count.should == 5
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should have all backtraces correctly formatted" do
|
127
|
+
@test_and_location.keys.each do |test_name|
|
128
|
+
@location_finder.to_hash[test_name].should == @test_and_location[test_name]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "shared between many files" do
|
134
|
+
before(:each) do
|
135
|
+
@files = ["spec/fixture/spec/shared_examples_spec.js", "spec/fixture/spec/call_to_shared_example_in_other_file_spec.js"]
|
136
|
+
@suite = JasmineParser::JasmineSuite.new
|
137
|
+
@parser = JasmineParser::FileParser.new(@suite)
|
138
|
+
@parser.parse @files
|
139
|
+
|
140
|
+
@location_finder = JasmineParser::LocationFiner.new @suite
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should be able to find the example shared between 2 files" do
|
145
|
+
tests = {
|
146
|
+
"call to a shared example that lives in another file example 1" => [
|
147
|
+
"spec/fixture/spec/shared_examples_spec.js:4:in `example 1'",
|
148
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:2:in `shared example on window'",
|
149
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:1:in `call to a shared example that lives in another file'"
|
150
|
+
],
|
151
|
+
"call to a shared example that lives in another file example 2" => [
|
152
|
+
"spec/fixture/spec/shared_examples_spec.js:7:in `example 2'",
|
153
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:2:in `shared example on window'",
|
154
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:1:in `call to a shared example that lives in another file'"
|
155
|
+
]
|
156
|
+
}
|
157
|
+
|
158
|
+
tests.keys.each do |test_name|
|
159
|
+
@location_finder.to_hash[test_name].should == tests[test_name]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should be able to share examples which are not nested in a group" do
|
164
|
+
tests = {
|
165
|
+
"call to a shared example that lives in another file and not nested example 3" => [
|
166
|
+
"spec/fixture/spec/shared_examples_spec.js:34:in `example 3'",
|
167
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:6:in `shared outside any group'",
|
168
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:5:in `call to a shared example that lives in another file and not nested'"
|
169
|
+
],
|
170
|
+
"call to a shared example that lives in another file and not nested example 4" => [
|
171
|
+
"spec/fixture/spec/shared_examples_spec.js:37:in `example 4'",
|
172
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:6:in `shared outside any group'",
|
173
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:5:in `call to a shared example that lives in another file and not nested'"
|
174
|
+
]
|
175
|
+
}
|
176
|
+
|
177
|
+
tests.keys.each do |test_name|
|
178
|
+
@location_finder.to_hash[test_name].should == tests[test_name]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should handle multiple shared examples in one group" do
|
183
|
+
tests = {
|
184
|
+
"multiple shared examples group 1 example 1" => [
|
185
|
+
"spec/fixture/spec/shared_examples_spec.js:4:in `example 1'",
|
186
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:11:in `shared example on window'",
|
187
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:10:in `group 1'",
|
188
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:9:in `multiple shared examples'"
|
189
|
+
],
|
190
|
+
"multiple shared examples group 2 example 4" => [
|
191
|
+
"spec/fixture/spec/shared_examples_spec.js:37:in `example 4'",
|
192
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:15:in `shared outside any group'",
|
193
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:14:in `group 2'",
|
194
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:9:in `multiple shared examples'"
|
195
|
+
]
|
196
|
+
}
|
197
|
+
|
198
|
+
tests.keys.each do |test_name|
|
199
|
+
@location_finder.to_hash[test_name].should == tests[test_name]
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should handle multiple nestings of shared examples" do
|
204
|
+
tests = {
|
205
|
+
"nested tests group 1 example 3" => [
|
206
|
+
"spec/fixture/spec/shared_examples_spec.js:34:in `example 3'",
|
207
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:37:in `shared outside any group'",
|
208
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:28:in `nested share level 2'",
|
209
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:22:in `nested share level 1'",
|
210
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:21:in `group 1'",
|
211
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:20:in `nested tests'"
|
212
|
+
],
|
213
|
+
"nested tests group 1 example 4" => [
|
214
|
+
"spec/fixture/spec/shared_examples_spec.js:37:in `example 4'",
|
215
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:37:in `shared outside any group'",
|
216
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:28:in `nested share level 2'",
|
217
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:22:in `nested share level 1'",
|
218
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:21:in `group 1'",
|
219
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:20:in `nested tests'"
|
220
|
+
],
|
221
|
+
"nested tests group 1 example 5" => [
|
222
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:30:in `example 5'",
|
223
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:22:in `nested share level 1'",
|
224
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:21:in `group 1'",
|
225
|
+
"spec/fixture/spec/call_to_shared_example_in_other_file_spec.js:20:in `nested tests'"
|
226
|
+
]
|
227
|
+
}
|
228
|
+
|
229
|
+
tests.keys.each do |test_name|
|
230
|
+
@location_finder.to_hash[test_name].should == tests[test_name]
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "Shared examples in function declaration" do
|
237
|
+
before(:each) do
|
238
|
+
@file = "spec/fixture/spec/shared_examples_function_declaration_spec.js"
|
239
|
+
@suite = JasmineParser::JasmineSuite.new
|
240
|
+
@parser = JasmineParser::FileParser.new(@suite)
|
241
|
+
@parser.parse [@file]
|
242
|
+
|
243
|
+
@location_finder = JasmineParser::LocationFiner.new @suite
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should have have 4 examples" do
|
247
|
+
@location_finder.example_count.should == 4
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should have all of the test names" do
|
251
|
+
test_names = [
|
252
|
+
"shared example declared in new function group 1 group 2 (shared) example 1",
|
253
|
+
"shared example declared in new function group 1 group 2 (shared) group 1.1 example 2",
|
254
|
+
"shared example declared in new function group 1 group 2 source example 3",
|
255
|
+
"shared example declared in new function group 1 group 3 example 4"
|
256
|
+
]
|
257
|
+
|
258
|
+
@location_finder.test_names.sort.should == test_names.sort
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# Copyright (c) 2013, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
require 'spec_helper'
|
32
|
+
|
33
|
+
|
34
|
+
describe JasmineParser::Node do
|
35
|
+
before(:each) do
|
36
|
+
|
37
|
+
@original_node = JasmineParser::Node.root({:filename => "foo.txt"})
|
38
|
+
|
39
|
+
@original_node.children << JasmineParser::Node.describe(:name => "describe", :parent => @original_node)
|
40
|
+
@original_node.children.first.children << JasmineParser::Node.it(:name => "nested it", :parent => @original_node.children.first)
|
41
|
+
@original_node.children << JasmineParser::Node.it(:name => "not nested it", :parent => @original_node)
|
42
|
+
|
43
|
+
@new_node = @original_node.clone
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return same type of node as original" do
|
47
|
+
@new_node.type.should == :root
|
48
|
+
@new_node.filename.should == "foo.txt"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should have the same amount of top level children" do
|
52
|
+
@new_node.children.size.should == 2
|
53
|
+
@new_node.children.first.name.should == "describe"
|
54
|
+
@new_node.children.first.type.should == :group
|
55
|
+
@new_node.children.last.type.should == :it
|
56
|
+
@new_node.children.last.name.should == "not nested it"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have copied the nested child" do
|
60
|
+
@new_node.children.first.children.first.type.should == :it
|
61
|
+
@new_node.children.first.children.first.name.should == "nested it"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not have any pointers to original node" do
|
65
|
+
@original_node.object_id.should_not == @new_node.object_id
|
66
|
+
@original_node.children.first.object_id.should_not == @new_node.children.first.object_id
|
67
|
+
@original_node.children.last.object_id.should_not == @new_node.children.last.object_id
|
68
|
+
@original_node.children.first.children.first.object_id.should_not == @new_node.children.first.children.first.object_id
|
69
|
+
end
|
70
|
+
|
71
|
+
context "types of nodes to be cloned" do
|
72
|
+
|
73
|
+
before(:each) do
|
74
|
+
@node_types = {
|
75
|
+
:root => :root,
|
76
|
+
:it => :it,
|
77
|
+
:context => :group,
|
78
|
+
:describe => :group,
|
79
|
+
:group => :group,
|
80
|
+
:shared_behavior_declaration => :shared_behavior_declaration,
|
81
|
+
:shared_behavior_invocation => :shared_behavior_invocation
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should support cloning of all node types" do
|
86
|
+
@node_types.keys.each do |key|
|
87
|
+
original = JasmineParser::Node.send(key, {:name => "node"})
|
88
|
+
new_node = original.clone
|
89
|
+
new_node.type.should == @node_types[key]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
context "updating parent of the newly cloned children" do
|
96
|
+
before(:each) do
|
97
|
+
@new_node_id = @new_node.object_id
|
98
|
+
@new_node_first_child_id = @new_node.children.first.object_id
|
99
|
+
@new_node_first_childs_child_id = @new_node.children.first.children.first.object_id
|
100
|
+
@new_node_last_child_id = @new_node.children.last.object_id
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not point to any objects on original node" do
|
105
|
+
@original_node.object_id.should_not == @new_node_id
|
106
|
+
@original_node.children.first.object_id.should_not == @new_node_first_child_id
|
107
|
+
@original_node.children.last.object_id.should_not == @new_node_last_child_id
|
108
|
+
@original_node.children.first.children.object_id.should_not == @new_node_first_childs_child_id
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should be pointing to correct parent from nested child" do
|
112
|
+
nested_child = @new_node.children.first.children.first
|
113
|
+
nested_child.parent.object_id.should == @new_node_first_child_id
|
114
|
+
nested_child.parent.parent.object_id.should == @new_node_id
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should be pointing to the correct parent for 2nd child" do
|
118
|
+
second_child = @new_node.children.last
|
119
|
+
second_child.parent.object_id.should == @new_node_id
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Copyright (c) 2013, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
require 'spec_helper'
|
32
|
+
|
33
|
+
|
34
|
+
describe JasmineParser::NodeCollector do
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
@node = JasmineParser::Node.root({:filename => "foo.txt"})
|
38
|
+
@node.children << JasmineParser::Node.group(:filename => "foo.txt")
|
39
|
+
@node.children.first.children << JasmineParser::Node.it(:line => 5, :name => "node 1")
|
40
|
+
@node.children.first.children << JasmineParser::Node.it(:line => 10, :name => "node 2")
|
41
|
+
@node.children.first.children << JasmineParser::Node.shared_behavior_invocation(:filename => "foo.txt")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be able to find the it node" do
|
45
|
+
collector = JasmineParser::NodeCollector.new([@node], :it)
|
46
|
+
collector.nodes.size.should == 2
|
47
|
+
collector.nodes.first.type.should == :it
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be able to find the :group node" do
|
51
|
+
collector = JasmineParser::NodeCollector.new([@node], :group)
|
52
|
+
collector.nodes.size.should == 1
|
53
|
+
collector.nodes.first.type.should == :group
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
it "should be able to find the :root node" do
|
58
|
+
collector = JasmineParser::NodeCollector.new([@node], :root)
|
59
|
+
collector.nodes.size.should == 1
|
60
|
+
collector.nodes.first.type.should == :root
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should be able to refine the search" do
|
64
|
+
collector = JasmineParser::NodeCollector.new([@node], :shared_behavior_invocation, {:adoptable? => false})
|
65
|
+
collector.nodes.size.should == 1
|
66
|
+
collector.nodes.first.type.should == :shared_behavior_invocation
|
67
|
+
collector.nodes.first.adoptable?.should == false
|
68
|
+
|
69
|
+
@node.children.first.children.last.adopted!
|
70
|
+
collector = JasmineParser::NodeCollector.new([@node], :shared_behavior_invocation, {:adoptable? => true})
|
71
|
+
collector.nodes.size.should == 1
|
72
|
+
collector.nodes.first.type.should == :shared_behavior_invocation
|
73
|
+
collector.nodes.first.adoptable?.should == true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be able to search by name" do
|
77
|
+
collector = JasmineParser::NodeCollector.new([@node], :it)
|
78
|
+
collector["node 1"].line.should == 5
|
79
|
+
collector["node 2"].line.should == 10
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return nil for node not found" do
|
83
|
+
collector = JasmineParser::NodeCollector.new([@node], :it)
|
84
|
+
collector["asfdsf"].nil?.should == true
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|