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.
Files changed (46) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +37 -0
  3. data/LICENSE.txt +29 -0
  4. data/README.md +118 -0
  5. data/Rakefile +43 -0
  6. data/jasmine-parser.gemspec +50 -0
  7. data/lib/jasmine-parser/announcer.rb +55 -0
  8. data/lib/jasmine-parser/config.rb +57 -0
  9. data/lib/jasmine-parser/exceptions.rb +46 -0
  10. data/lib/jasmine-parser/file_parser.rb +62 -0
  11. data/lib/jasmine-parser/jasmine_suite.rb +69 -0
  12. data/lib/jasmine-parser/javascript_object_wrapper.rb +136 -0
  13. data/lib/jasmine-parser/location_finder.rb +100 -0
  14. data/lib/jasmine-parser/node_collector.rb +88 -0
  15. data/lib/jasmine-parser/node_factory.rb +121 -0
  16. data/lib/jasmine-parser/nodes/example_node.rb +40 -0
  17. data/lib/jasmine-parser/nodes/function_invocation_node.rb +70 -0
  18. data/lib/jasmine-parser/nodes/group_node.rb +40 -0
  19. data/lib/jasmine-parser/nodes/node.rb +120 -0
  20. data/lib/jasmine-parser/nodes/root_node.rb +40 -0
  21. data/lib/jasmine-parser/nodes/shared_behavior_decl_node.rb +54 -0
  22. data/lib/jasmine-parser/nodes/shared_behavior_invoc_node.rb +80 -0
  23. data/lib/jasmine-parser.rb +53 -0
  24. data/spec/end_to_end_suite_parser_spec.rb +100 -0
  25. data/spec/file_parser_spec.rb +68 -0
  26. data/spec/fixture/spec/call_to_shared_example_in_other_file_spec.js +38 -0
  27. data/spec/fixture/spec/empty_shared_examples_spec.js +21 -0
  28. data/spec/fixture/spec/example_spec.js +48 -0
  29. data/spec/fixture/spec/example_spec_with_strange_spacing.js +48 -0
  30. data/spec/fixture/spec/multi_declaration_shared_spec.js +26 -0
  31. data/spec/fixture/spec/not_properly_formatted.js +24 -0
  32. data/spec/fixture/spec/shared_examples_function_declaration_spec.js +49 -0
  33. data/spec/fixture/spec/shared_examples_spec.js +43 -0
  34. data/spec/fixture/spec/small_file.js +5 -0
  35. data/spec/location_finder_spec.rb +263 -0
  36. data/spec/node_cloning_spec.rb +123 -0
  37. data/spec/node_collector_spec.rb +87 -0
  38. data/spec/node_spec.rb +102 -0
  39. data/spec/shared_behavior_decl_node_spec.rb +59 -0
  40. data/spec/shared_behavior_invoc_node_spec.rb +129 -0
  41. data/spec/shared_examples_for_end_to_end.rb +239 -0
  42. data/spec/shared_examples_in_new_function_spec.rb +74 -0
  43. data/spec/shared_examples_spec.rb +71 -0
  44. data/spec/spec_helper.rb +54 -0
  45. data/spec/suite_spec.rb +70 -0
  46. metadata +128 -0
@@ -0,0 +1,120 @@
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
+ module JasmineParser
32
+
33
+ class Node
34
+
35
+
36
+ attr_reader :name, :line, :filename, :js_object
37
+ attr_accessor :parent, :children
38
+ def initialize(args)
39
+
40
+ @name = args[:name]
41
+ @line = args[:line]
42
+ @parent = args[:parent]
43
+ @children = args[:children] || []
44
+ @filename = args[:filename]
45
+ @js_object = args[:js_object]
46
+
47
+ end
48
+
49
+ def type
50
+ raise UndefinedMethodError
51
+ end
52
+
53
+ def self.root(args)
54
+ RootNode.new args
55
+ end
56
+
57
+ def self.it(args)
58
+ ExampleNode.new args
59
+ end
60
+
61
+ def self.group(args)
62
+ GroupNode.new args
63
+ end
64
+
65
+ class << self
66
+ alias context group
67
+ alias describe group
68
+ end
69
+
70
+ def self.shared_behavior_declaration(args)
71
+ SharedBehaviorDeclaration.new args
72
+ end
73
+
74
+ def self.shared_behavior_invocation(args)
75
+ SharedBehaviorInvocation.new args
76
+ end
77
+
78
+ def self.function_invocation(args)
79
+ FunctionInvocation.new args
80
+ end
81
+
82
+ def clone
83
+ args = {
84
+ :name => name,
85
+ :line => line,
86
+ :parent => parent,
87
+ :children => [],
88
+ :filename => filename,
89
+ :js_object => js_object
90
+ }
91
+
92
+ new_clone = Node.send(self.type, args)
93
+
94
+ self.children.each do |child|
95
+ new_clone.children << child.clone
96
+ end
97
+
98
+ update_the_parent_for_all_children(new_clone)
99
+
100
+ new_clone
101
+ end
102
+
103
+ def formatted_name
104
+ name + " "
105
+ end
106
+
107
+ def ready_to_be_adopted?
108
+ true
109
+ end
110
+
111
+ private
112
+
113
+ def update_the_parent_for_all_children(node)
114
+ node.children.each do |child|
115
+ child.parent = node
116
+ end
117
+ end
118
+ end
119
+
120
+ end
@@ -0,0 +1,40 @@
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
+ module JasmineParser
32
+
33
+ class RootNode < Node
34
+
35
+ def type
36
+ :root
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,54 @@
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
+ module JasmineParser
32
+ class SharedBehaviorDeclaration < Node
33
+ def type
34
+ :shared_behavior_declaration
35
+ end
36
+
37
+ #TODO: Export delete! to module
38
+ #ToDo: write tests for delete method
39
+ def delete!
40
+ self.parent.children.delete(self)
41
+ self.parent = nil
42
+ end
43
+
44
+ #ToDo: write tests for ready_to_be_adopted?
45
+ def ready_to_be_adopted?
46
+ not_ready_to_be_adopted = children.collect do |child|
47
+ child if child.type == :shared_behavior_invocation and child.ready_to_be_adopted? == false
48
+ end.compact
49
+
50
+ not_ready_to_be_adopted.empty?
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,80 @@
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
+ module JasmineParser
32
+ class SharedBehaviorInvocation < Node
33
+ def type
34
+ :shared_behavior_invocation
35
+ end
36
+
37
+
38
+ def initialize(args)
39
+ super
40
+ @adoptable = false
41
+ end
42
+
43
+ def adoptable?
44
+ @adoptable
45
+ end
46
+
47
+ alias :ready_to_be_adopted? :adoptable?
48
+
49
+ def adopted!
50
+ @adoptable = true
51
+ end
52
+
53
+
54
+
55
+ attr_accessor :name
56
+ def adopt_children(former_parent_node)
57
+ raise UnsupportedObjectType unless former_parent_node.kind_of? Node
58
+ return true if adoptable?
59
+
60
+ return false unless former_parent_node.ready_to_be_adopted?
61
+
62
+ former_parent_node.clone.children.each {|child| self.children << child }
63
+
64
+ update_the_parent_for_all_children(self)
65
+ adopted!
66
+ end
67
+
68
+
69
+ def formatted_name
70
+ nil
71
+ end
72
+
73
+ private
74
+
75
+ def find_location_on_parent
76
+ self.parent.children.index(self)
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,53 @@
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
+
32
+ jasmine_parser_files = ['config',
33
+ 'announcer',
34
+ 'exceptions',
35
+ 'nodes/node',
36
+ 'nodes/root_node',
37
+ 'nodes/example_node',
38
+ 'nodes/group_node',
39
+ 'nodes/shared_behavior_decl_node',
40
+ 'nodes/shared_behavior_invoc_node',
41
+ 'nodes/function_invocation_node',
42
+ 'node_collector',
43
+ 'javascript_object_wrapper',
44
+ 'node_factory',
45
+ 'jasmine_suite',
46
+ 'file_parser',
47
+ 'location_finder'
48
+ ]
49
+
50
+
51
+ jasmine_parser_files.each do |file|
52
+ require File.join('jasmine-parser', file)
53
+ end
@@ -0,0 +1,100 @@
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
+ require 'shared_examples_for_end_to_end'
33
+
34
+ describe "parsing well formatted, single file" do
35
+ before(:each) do
36
+ @filename = "spec/fixture/spec/example_spec.js"
37
+ @suite = JasmineParser::JasmineSuite.new
38
+ @parser = JasmineParser::FileParser.new(@suite)
39
+ @parser.parse [@filename]
40
+ @file_count = 1
41
+ end
42
+
43
+ it_behaves_like "In depth tests of nodes"
44
+
45
+ end
46
+
47
+
48
+ describe "parsing poorly formatted, single file" do
49
+ before(:each) do
50
+ @filename = "spec/fixture/spec/example_spec_with_strange_spacing.js"
51
+ @suite = JasmineParser::JasmineSuite.new
52
+ @parser = JasmineParser::FileParser.new(@suite)
53
+ @parser.parse [@filename]
54
+ @file_count = 1
55
+ end
56
+
57
+ it_behaves_like "In depth tests of nodes"
58
+
59
+ end
60
+
61
+ describe "multi file parsing" do
62
+ before(:each) do
63
+ @file_1 = "spec/fixture/spec/example_spec.js"
64
+ @file_2 = "spec/fixture/spec/small_file.js"
65
+ @suite = JasmineParser::JasmineSuite.new
66
+ @parser = JasmineParser::FileParser.new(@suite)
67
+ @parser.parse [@file_1,
68
+ @file_2]
69
+ @file_count = 2
70
+ end
71
+
72
+ describe "individual file tests for first file" do
73
+ before(:each) do
74
+ @filename = @file_1
75
+ end
76
+
77
+ it_behaves_like "In depth tests of nodes"
78
+ end
79
+
80
+ describe "individual file tests for second file" do
81
+ describe "root node" do
82
+ before(:each) do
83
+ @node = @suite.spec_files.last
84
+
85
+ @node_name = ""
86
+ @node_type = :root
87
+ @node_line = 0
88
+ @node_final_line = 5
89
+ @node_parent = nil
90
+ @node_filename = @file_2
91
+ @node_children_count = 1
92
+
93
+ end
94
+
95
+ it_behaves_like "node info tests"
96
+ end
97
+ end
98
+
99
+
100
+ end
@@ -0,0 +1,68 @@
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
+ describe JasmineParser::FileParser do
34
+
35
+ before(:each) do
36
+ @suite = JasmineParser::JasmineSuite.new
37
+ @parser = JasmineParser::FileParser.new(@suite)
38
+ end
39
+
40
+
41
+ describe "parsing command" do
42
+
43
+ it "should not accept strings for file name input" do
44
+ expect {@parser.parse "foo"}.to raise_error JasmineParser::WrongArgumentTypeForFileParser
45
+ end
46
+
47
+ it "should not accept files that do not exist" do
48
+ expect {@parser.parse ["foo"]}.to raise_error JasmineParser::FileDoesNotExistError
49
+ end
50
+
51
+ it "should parse existing file" do
52
+ @parser.parse ["spec/fixture/spec/example_spec.js"]
53
+ end
54
+ end
55
+
56
+ describe "suite object" do
57
+ before(:each) do
58
+ @parser.parse ["spec/fixture/spec/example_spec.js"]
59
+ end
60
+
61
+ it "should contain children" do
62
+ @suite.spec_files.size.should == 1
63
+ end
64
+
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,38 @@
1
+ describe("call to a shared example that lives in another file", function(){
2
+ itBehavesLike('shared example on window');
3
+ })
4
+
5
+ describe("call to a shared example that lives in another file and not nested", function(){
6
+ itBehavesLike('shared outside any group');
7
+ })
8
+
9
+ describe("multiple shared examples", function(){
10
+ context("group 1", function(){
11
+ itBehavesLike('shared example on window');
12
+ })
13
+
14
+ context("group 2", function(){
15
+ itBehavesLike('shared outside any group');
16
+ })
17
+
18
+ })
19
+
20
+ describe("nested tests", function(){
21
+ context("group 1", function(){
22
+ itBehavesLike("nested share level 1")
23
+ })
24
+ })
25
+
26
+
27
+ sharedExamplesFor("nested share level 1", function() {
28
+ itBehavesLike('nested share level 2');
29
+
30
+ it("example 5", function(){
31
+ expect(true).toBe(true);
32
+ })
33
+
34
+ });
35
+
36
+ sharedExamplesFor("nested share level 2", function() {
37
+ itBehavesLike('shared outside any group');
38
+ });
@@ -0,0 +1,21 @@
1
+ describe('node containing empty shared examples', function() {
2
+ function sharedBehavior(someMethod) {
3
+ var foo = 1;
4
+ }
5
+
6
+
7
+ describe("group that needs shared example", function() {
8
+ sharedBehavior(someMethod);
9
+
10
+ describe("group that does not use shared example", function() {
11
+ it("test that does not use shared example", function() {
12
+ expect(true).toBe(true);
13
+ });
14
+ });
15
+ });
16
+
17
+ //Stolen from http://robots.thoughtbot.com/post/9611103221/jasmine-and-shared-examples
18
+ window.itShouldBehaveLike = function() {
19
+ var foo = 1;
20
+ };
21
+ })
@@ -0,0 +1,48 @@
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
+
12
+ context('context group', function(){
13
+ describe('nested group in context', function(){
14
+ it("should be here for nested context", function(){
15
+ expect(true).toBe(true);
16
+ })
17
+ })
18
+ })
19
+ })
20
+
21
+ describe("example with return", function(){
22
+ return describe("return example_spec", function(){
23
+ return it("should have example name with return upfront", function(){
24
+ expect(true).toBe(true);
25
+ })
26
+
27
+ return context("return context", function(){
28
+ describe("group inside return context", function(){
29
+ it("should be here for nested context with return", function(){
30
+ expect(true).toBe(true);
31
+ })
32
+ })
33
+ })
34
+ })
35
+ })
36
+
37
+ context("root context", function(){
38
+ describe("nested_group in context", function(){
39
+ it("spec in context", function(){
40
+ expect(true).toBe(true);
41
+ })
42
+ })
43
+ })
44
+
45
+
46
+
47
+
48
+ //this are just notes
@@ -0,0 +1,48 @@
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
+
12
+ context('context group', function(){
13
+ describe('nested group in context', function(){
14
+ it("should be here for nested context", function(){
15
+ expect(true).toBe(true);
16
+ })
17
+ })
18
+ })
19
+ })
20
+
21
+ describe("example with return", function(){
22
+ return describe("return example_spec", function(){
23
+ return it("should have example name with return upfront", function(){
24
+ expect(true).toBe(true);
25
+ })
26
+
27
+ return context("return context", function(){
28
+ describe("group inside return context", function(){
29
+ it("should be here for nested context with return", function(){
30
+ expect(true).toBe(true);
31
+ })
32
+ })
33
+ })
34
+ })
35
+ })
36
+
37
+ context("root context", function(){
38
+ describe("nested_group in context", function(){
39
+ it("spec in context", function(){
40
+ expect(true).toBe(true);
41
+ })
42
+ })
43
+ })
44
+
45
+
46
+
47
+
48
+ //this are just notes