jasmine-parser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.idea
|
data/Gemfile
ADDED
@@ -0,0 +1,37 @@
|
|
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
|
+
source "http://rubygems.org"
|
32
|
+
gemspec
|
33
|
+
|
34
|
+
group :development, :test do
|
35
|
+
gem "rspec"
|
36
|
+
gem "rspec_junit_formatter"
|
37
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,29 @@
|
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
Jasmine-Parser
|
2
|
+
==============
|
3
|
+
|
4
|
+
### Jasmine-Parser will read through all of the _spec.js files, creating a dependency tree of all the describe/context/it blocks. It will also try to merge any shared examples that are spread through the files, generating a full stack trace for any given test.
|
5
|
+
|
6
|
+
|
7
|
+
Problem
|
8
|
+
-------
|
9
|
+
|
10
|
+
Jasmine is a great tool for testing Javascript. However, outside of Firefox, no browser reliably supports backt races for any given test failures.
|
11
|
+
|
12
|
+
This means that, when a test fails on Internet Explorer, all you have is a full test name in the test results. This becomes complicated when a test is using shared examples from other files.
|
13
|
+
|
14
|
+
The idea is to drop in this gem into the testing gem and provide the backtrace to all of the tests in the background.
|
15
|
+
|
16
|
+
|
17
|
+
### Standard error in console when a test fails
|
18
|
+
> 1)
|
19
|
+
|
20
|
+
> RuntimeError in 'Some long test Example Name'
|
21
|
+
|
22
|
+
> Expected true to be false.
|
23
|
+
|
24
|
+
>
|
25
|
+
|
26
|
+
> ../jasmine-1.2.1/lib/jasmine/rspec_formatter.rb:41:in `declare_spec'
|
27
|
+
|
28
|
+
> ../jasmine-1.2.1/lib/jasmine/rspec_formatter.rb:72:in `report_spec'
|
29
|
+
|
30
|
+
> ../jasmine-1.2.1/lib/jasmine/rspec_formatter.rb:42:in `declare_spec'
|
31
|
+
|
32
|
+
|
33
|
+
### After jasmine-parser integration
|
34
|
+
> 1)
|
35
|
+
|
36
|
+
> RuntimeError in 'Some long test Example Name'
|
37
|
+
|
38
|
+
> Expected true to be false.
|
39
|
+
|
40
|
+
>
|
41
|
+
|
42
|
+
> ../project/spec/javascripts/test_spec.js:119:in `Name'
|
43
|
+
|
44
|
+
> ../project/spec/javascripts/test_spec.js:104:in `(shared examples)'
|
45
|
+
|
46
|
+
> ../project/spec/javascripts/test_spec.js:202:in `Example'
|
47
|
+
|
48
|
+
> ../project/spec/javascripts/test_spec.js:201:in `test'
|
49
|
+
|
50
|
+
> ../project/spec/javascripts/test_spec.js:99:in `long'
|
51
|
+
|
52
|
+
> ../project/spec/javascripts/test_spec.js:1:in `Some'
|
53
|
+
|
54
|
+
> ../jasmine-1.2.1/lib/jasmine/rspec_formatter.rb:72:in `report_spec'
|
55
|
+
|
56
|
+
> ../jasmine-1.2.1/lib/jasmine/rspec_formatter.rb:42:in `declare_spec'
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
Installation
|
61
|
+
------------
|
62
|
+
|
63
|
+
> gem install jasmine-parser
|
64
|
+
|
65
|
+
|
66
|
+
Using
|
67
|
+
-----
|
68
|
+
|
69
|
+
Declare a suite object
|
70
|
+
|
71
|
+
> suite = JasmineParser::JasmineSuite.new
|
72
|
+
|
73
|
+
Create a parser instance
|
74
|
+
|
75
|
+
> parser = JasmineParser::FileParser.new(suite)
|
76
|
+
|
77
|
+
Pass in an Array of files to be parsed
|
78
|
+
|
79
|
+
> parser.parse [file1, file2, file3]
|
80
|
+
|
81
|
+
After the parsing is complete, the JasmineSuite object has ability to query the test info
|
82
|
+
|
83
|
+
> suite.example_count #=> Total count of examples discovered
|
84
|
+
|
85
|
+
> suite.example_names #=> Array of all test names discovered
|
86
|
+
|
87
|
+
> suite.find_spec_location("Example name") #=> Array of file:line backtraces in order test files were called
|
88
|
+
|
89
|
+
> suite["Example name"] #=> An alias of "find_spec_location" method
|
90
|
+
|
91
|
+
|
92
|
+
Shared Examples
|
93
|
+
---------------
|
94
|
+
|
95
|
+
We try to automatically figure out when tests are declaring a block of shared examples, or when calling those in a later location.
|
96
|
+
|
97
|
+
Since there is no standard method for doing this, like there is in Rspec, this can get challenging. To cover as many scenarios as possible, we try to support both common ways of dealing with shared examples.
|
98
|
+
|
99
|
+
### Function declaration
|
100
|
+
|
101
|
+
Any function that is declared in the _spec.js files are treated as a possible container of shared examples. We store this function as such, and during the merging of shared examples stage, try to see if there are any references to that function. If there is, we try to find any "it" nodes inside, and build a backtrace from that.
|
102
|
+
|
103
|
+
### Storing shared methods on the window
|
104
|
+
In this article, the author recommends to store the shared examples on the window http://robots.thoughtbot.com/post/9611103221/jasmine-and-shared-examples
|
105
|
+
|
106
|
+
However, this is not the only way to solve this problem. We have inserted several commonly used shared example method names, but you can add more to the list.
|
107
|
+
|
108
|
+
Default shared example declarations: ["sharedExamples", "sharedExamplesFor"]
|
109
|
+
To add the names you use
|
110
|
+
JasmineParser::Config.shared_behavior_declarations << "Something"
|
111
|
+
|
112
|
+
|
113
|
+
Default shared example invocations: ["itShouldBehaveLike", "itBehavesLike"]
|
114
|
+
To add the names you use
|
115
|
+
JasmineParser::Config.shared_behavior_invocation << "Something"
|
116
|
+
|
117
|
+
|
118
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
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
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
|
32
|
+
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/lib")
|
33
|
+
require "bundler"
|
34
|
+
Bundler::GemHelper.install_tasks
|
35
|
+
|
36
|
+
require 'rspec'
|
37
|
+
require 'rspec/core/rake_task'
|
38
|
+
|
39
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
40
|
+
t.pattern = 'spec/**/*_spec.rb'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
@@ -0,0 +1,50 @@
|
|
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
|
+
Gem::Specification.new do |s|
|
32
|
+
s.name = "jasmine-parser"
|
33
|
+
s.version = "0.0.1"
|
34
|
+
s.default_executable = "jasmine-parser"
|
35
|
+
|
36
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
37
|
+
s.authors = ["Dima Kovalenko"]
|
38
|
+
s.date = %q{2012-12-03}
|
39
|
+
s.description = %q{Parser for Jasmine Spec Files}
|
40
|
+
s.email = %q{dima.kovalenko@gmail.com}
|
41
|
+
files = `git ls-files`.split("\n") | Dir.glob('jasmine-parser/**/*')
|
42
|
+
files.delete "Gemfile.lock"
|
43
|
+
s.files = files
|
44
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
45
|
+
s.homepage = %q{https://github.com/groupon/jasmine-parser}
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = %q{1.6.2}
|
48
|
+
s.summary = %q{Gem to help to parse all of the jasmine spec files, and create usable stack traces for any given test.}
|
49
|
+
s.add_dependency 'rkelly'
|
50
|
+
end
|
@@ -0,0 +1,55 @@
|
|
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 Announcer
|
34
|
+
|
35
|
+
def self.info(message)
|
36
|
+
return nil unless Config.logging.include? :info
|
37
|
+
puts "[INFO] #{message}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.warning(message)
|
41
|
+
@warning_count ||= 0
|
42
|
+
@warning_count = @warning_count + 1
|
43
|
+
return nil unless Config.logging.include? :warning
|
44
|
+
puts "[WARNING - #{@warning_count}] #{message}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.error(message)
|
48
|
+
@error_count ||= 0
|
49
|
+
@error_count = @error_count + 1
|
50
|
+
return nil unless Config.logging.include? :error
|
51
|
+
puts "[ERROR - #{@error_count}] #{message}"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,57 @@
|
|
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 Config
|
33
|
+
|
34
|
+
#Some common names for shared behavior, add more that apply to your project
|
35
|
+
def self.shared_behavior_declarations
|
36
|
+
@shared_behavior_declarations ||= ["sharedExamples", "sharedExamplesFor"]
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def self.shared_behavior_invocation
|
41
|
+
@shared_behavior_invocation ||= ["itShouldBehaveLike", "itBehavesLike"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.reserved_group_example_words
|
45
|
+
["context", "describe", "it"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.logging
|
49
|
+
@logging ||= [:info, :warning, :error]
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.logging=(value)
|
53
|
+
@logging = value
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,46 @@
|
|
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 FileParserError < StandardError; end
|
34
|
+
class WrongArgumentTypeForFileParser < FileParserError; end
|
35
|
+
class FileDoesNotExistError < FileParserError; end
|
36
|
+
|
37
|
+
class NodeFactoryError < StandardError; end
|
38
|
+
class NodeTypeCannotBeBlankOrNilError < NodeFactoryError; end
|
39
|
+
class NodeStartLineHasToBeIntegerOrNilError < NodeFactoryError; end
|
40
|
+
class NodeFinalLineHasToBeIntegerOrNilError < NodeFactoryError; end
|
41
|
+
|
42
|
+
|
43
|
+
class NodeError < StandardError; end
|
44
|
+
class UndefinedMethodError < NodeError; end
|
45
|
+
class UnsupportedObjectType < NodeError; end
|
46
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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 FileParser
|
34
|
+
|
35
|
+
attr_accessor :suite
|
36
|
+
def initialize(suite)
|
37
|
+
@suite = suite
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse(files)
|
41
|
+
raise WrongArgumentTypeForFileParser unless files.kind_of? Array
|
42
|
+
Announcer.info "Parsing #{files.size} spec files"
|
43
|
+
files.each do |filename|
|
44
|
+
raise FileDoesNotExistError unless File.exist? filename
|
45
|
+
#TODO: make this parallel if possible
|
46
|
+
#ToDO: think of caching of files for large projects
|
47
|
+
suite.add_spec_file(parse_file(filename))
|
48
|
+
end
|
49
|
+
Announcer.info "#{suite.example_count} examples found"
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def parse_file(filename)
|
56
|
+
NodeFactory.parse_file filename
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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 JasmineSuite
|
34
|
+
|
35
|
+
attr_reader :spec_files
|
36
|
+
def initialize
|
37
|
+
@spec_files = []
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_spec_file(file_object)
|
41
|
+
@spec_files << file_object
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_spec_location(spec_description)
|
45
|
+
spec_description = spec_description.strip
|
46
|
+
return location_finder.all_examples[spec_description] if location_finder.all_examples[spec_description]
|
47
|
+
Announcer.warning("Could not find the location for this example name\n'#{spec_description}'")
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
alias :[] :find_spec_location
|
52
|
+
|
53
|
+
def example_count
|
54
|
+
location_finder.example_count
|
55
|
+
end
|
56
|
+
|
57
|
+
def example_names
|
58
|
+
location_finder.test_names
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def location_finder
|
64
|
+
@location_finder ||= LocationFiner.new(self)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|