test_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 +4 -0
- data/.rvmrc +47 -0
- data/Gemfile +9 -0
- data/Rakefile +14 -0
- data/bin/test_parser +6 -0
- data/lib/test_parser/common.rb +17 -0
- data/lib/test_parser/extensions/minitest.rb +7 -0
- data/lib/test_parser/extensions/rspec.rb +16 -0
- data/lib/test_parser/minitest.rb +48 -0
- data/lib/test_parser/rspec.rb +68 -0
- data/lib/test_parser/snippet.rb +15 -0
- data/lib/test_parser/source_code.rb +40 -0
- data/lib/test_parser/test_information.rb +3 -0
- data/lib/test_parser/version.rb +3 -0
- data/lib/test_parser.rb +35 -0
- data/spec/minitest_spec.rb +39 -0
- data/spec/rspec_spec.rb +35 -0
- data/spec/source_code_spec.rb +66 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/matchers/match_code.rb +10 -0
- data/spec/support/projects_paths.rb +13 -0
- data/spec/test_parser_spec.rb +60 -0
- data/test/rspec_test.rb +24 -0
- data/test_parser.gemspec +27 -0
- data/test_project/Rakefile +14 -0
- data/test_project/life.rb +7 -0
- data/test_project/spec/example_spec.rb +14 -0
- data/test_project/spec/spec_helper.rb +1 -0
- data/test_project/test/example_test.rb +12 -0
- data/test_project/test/test_helper.rb +9 -0
- metadata +136 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.2-p180@test_parser"
|
8
|
+
|
9
|
+
#
|
10
|
+
# First we attempt to load the desired environment directly from the environment
|
11
|
+
# file. This is very fast and efficicent compared to running through the entire
|
12
|
+
# CLI and selector. If you want feedback on which environment was used then
|
13
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
14
|
+
#
|
15
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
16
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
|
17
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
18
|
+
else
|
19
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
20
|
+
rvm --create use "$environment_id"
|
21
|
+
fi
|
22
|
+
|
23
|
+
#
|
24
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
25
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
26
|
+
# necessary.
|
27
|
+
#
|
28
|
+
# filename=".gems"
|
29
|
+
# if [[ -s "$filename" ]] ; then
|
30
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
31
|
+
# fi
|
32
|
+
|
33
|
+
#
|
34
|
+
# If you use bundler and would like to run bundle each time you enter the
|
35
|
+
# directory, you can uncomment the following code.
|
36
|
+
#
|
37
|
+
# # Ensure that Bundler is installed. Install it if it is not.
|
38
|
+
# if ! command -v bundle >/dev/null; then
|
39
|
+
# printf "The rubygem 'bundler' is not installed. Installing it now.\n"
|
40
|
+
# gem install bundler
|
41
|
+
# fi
|
42
|
+
#
|
43
|
+
# # Bundle while reducing excess noise.
|
44
|
+
# printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
|
45
|
+
# bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
|
46
|
+
#
|
47
|
+
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.pattern = "test/*_test.rb"
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new
|
13
|
+
|
14
|
+
task :default => [:test, :spec]
|
data/bin/test_parser
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_parser/source_code'
|
2
|
+
require 'test_parser/test_information'
|
3
|
+
|
4
|
+
module TestParser
|
5
|
+
|
6
|
+
module Common
|
7
|
+
|
8
|
+
def build_test(extras = {})
|
9
|
+
TestInformation.new(parser_type, test_identification, test_file_name, extras)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_source_code
|
13
|
+
SourceCode.for(test_file_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RSpec
|
2
|
+
|
3
|
+
def self.world=(new_world)
|
4
|
+
@world = new_world
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.with_world(world)
|
8
|
+
old_world, self.world = self.world, world
|
9
|
+
result = yield(world)
|
10
|
+
self.world = old_world
|
11
|
+
result
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec::Core::Runner.disable_autorun!
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'minitest/unit'
|
2
|
+
require_relative 'extensions/minitest'
|
3
|
+
|
4
|
+
require 'test_parser'
|
5
|
+
|
6
|
+
module TestParser
|
7
|
+
class MiniTest
|
8
|
+
attr_reader :klass, :test_method
|
9
|
+
|
10
|
+
def self.find_tests!(path, options = {})
|
11
|
+
glob = options[:glob] || 'test/**/*_test.rb'
|
12
|
+
|
13
|
+
::MiniTest::Unit.dont_install_at_exit!
|
14
|
+
|
15
|
+
TestParser.require_all(path, glob)
|
16
|
+
|
17
|
+
::MiniTest::Unit::TestCase.test_suites.collect_concat do |klass|
|
18
|
+
klass.test_methods.map do |test|
|
19
|
+
new(klass, test).test_info
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
include Common
|
25
|
+
|
26
|
+
def parser_type
|
27
|
+
:minitest
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(klass, test_method)
|
31
|
+
@klass, @test_method = klass, test_method
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_info
|
35
|
+
build_test(:method_name => test_method)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_identification
|
39
|
+
"#{klass.name}##{test_method}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_file_name
|
43
|
+
klass.instance_method(test_method).source_location.first
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
require_relative 'extensions/rspec'
|
3
|
+
|
4
|
+
require 'test_parser'
|
5
|
+
|
6
|
+
module TestParser
|
7
|
+
class RSpec
|
8
|
+
attr_reader :example
|
9
|
+
|
10
|
+
def self.find_tests!(path, options = {})
|
11
|
+
glob = options[:glob] || 'spec/**/*_spec.rb'
|
12
|
+
|
13
|
+
::RSpec.with_world ::RSpec::Core::World.new do |world|
|
14
|
+
|
15
|
+
TestParser.require_all(path, glob)
|
16
|
+
|
17
|
+
groups = world.example_groups
|
18
|
+
examples = groups.collect_concat(&:descendant_filtered_examples)
|
19
|
+
examples.map do |example|
|
20
|
+
new(example).test_info
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
include Common
|
26
|
+
|
27
|
+
def initialize(example)
|
28
|
+
@example = example
|
29
|
+
end
|
30
|
+
|
31
|
+
def parser_type
|
32
|
+
:rspec2
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_info
|
36
|
+
build_test(:line_number => line_number)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_snippet
|
40
|
+
@test_snippet ||= test_source_code.extract_code_from_line(line_number)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_file_name
|
44
|
+
example.file_path
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_identification
|
48
|
+
(example_group_names.reverse + [example_description]).join('/')
|
49
|
+
end
|
50
|
+
|
51
|
+
def line_number
|
52
|
+
example.metadata[:line_number]
|
53
|
+
end
|
54
|
+
|
55
|
+
def example_group_names
|
56
|
+
example.example_group.ancestors.map(&:display_name)
|
57
|
+
end
|
58
|
+
|
59
|
+
def example_description
|
60
|
+
unless example.description.empty?
|
61
|
+
example.description
|
62
|
+
else
|
63
|
+
test_snippet.get_block.to_code
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'ruby_parser'
|
2
|
+
require 'test_parser/snippet'
|
3
|
+
|
4
|
+
module TestParser
|
5
|
+
|
6
|
+
class SourceCode < Snippet
|
7
|
+
|
8
|
+
def self.source_codes
|
9
|
+
@source_codes ||= begin
|
10
|
+
parser = RubyParser.new
|
11
|
+
Hash.new do |h, k|
|
12
|
+
h[k] = new(parser.parse File.read(k))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.clear_cache
|
18
|
+
@source_codes = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.for(filename)
|
22
|
+
source_codes[File.expand_path(filename)]
|
23
|
+
end
|
24
|
+
|
25
|
+
def extract_method(name)
|
26
|
+
name = name.to_sym
|
27
|
+
definitions = sexp.enum_for(:each_of_type, :defn)
|
28
|
+
method_sexp = definitions.find {|def_sexp| def_sexp[1] == name }
|
29
|
+
Snippet.new(method_sexp)
|
30
|
+
end
|
31
|
+
|
32
|
+
def extract_code_from_line(line_number)
|
33
|
+
method_calls = sexp.enum_for(:each_of_type, :iter)
|
34
|
+
code_sexp = method_calls.find {|sexp| sexp[1].line == line_number }
|
35
|
+
Snippet.new(code_sexp)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/test_parser.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_parser/common'
|
2
|
+
require 'test_parser/minitest'
|
3
|
+
require 'test_parser/rspec'
|
4
|
+
|
5
|
+
module TestParser
|
6
|
+
|
7
|
+
def all_tests(path, options = {})
|
8
|
+
frameworks = options[:frameworks] ||= [:rspec, :minitest]
|
9
|
+
path = sanitize_path(path)
|
10
|
+
frameworks.collect_concat do |framework|
|
11
|
+
send "#{framework}_tests", path, options[framework]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def minitest_tests(path, options = nil)
|
16
|
+
options ||= {}
|
17
|
+
MiniTest.find_tests!(path, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def rspec_tests(path, options = nil)
|
21
|
+
options ||= {}
|
22
|
+
RSpec.find_tests!(path, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def require_all(path, glob)
|
26
|
+
Dir[sanitize_path(path) + glob].each {|f| require f }
|
27
|
+
end
|
28
|
+
|
29
|
+
def sanitize_path(path)
|
30
|
+
return path if path.is_a? Pathname
|
31
|
+
Pathname.new(path).expand_path
|
32
|
+
end
|
33
|
+
|
34
|
+
extend self
|
35
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'test_parser'
|
4
|
+
describe TestParser::MiniTest do
|
5
|
+
before(:all) do
|
6
|
+
MiniTest::Unit::TestCase.reset
|
7
|
+
end
|
8
|
+
after(:all) do
|
9
|
+
MiniTest::Unit::TestCase.reset
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.find_tests!' do
|
13
|
+
|
14
|
+
context 'within test_project' do
|
15
|
+
before(:all) do
|
16
|
+
@tests = TestParser::MiniTest.find_tests! path_for_test_project
|
17
|
+
@test_identifications = @tests.map(&:identification)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'finds all the tests' do
|
21
|
+
@tests.should have(2).tests
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'finds normally declared test' do
|
25
|
+
@test_identifications.should include('TestSomething#test_foo')
|
26
|
+
test = @tests[@test_identifications.index('TestSomething#test_foo')]
|
27
|
+
test.file.should == (path_for_test_project('test/example_test.rb')).to_s
|
28
|
+
test.extras[:method_name].should == 'test_foo'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'finds module shared tests' do
|
32
|
+
@test_identifications.should include('TestSomething#test_truth')
|
33
|
+
test = @tests[@test_identifications.index('TestSomething#test_truth')]
|
34
|
+
test.file.should == (path_for_test_project('test/test_helper.rb')).to_s
|
35
|
+
test.extras[:method_name].should == 'test_truth'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/rspec_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'test_parser/rspec'
|
4
|
+
|
5
|
+
describe TestParser::RSpec do
|
6
|
+
describe '.find_test_suite!' do
|
7
|
+
context 'within test_project' do
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@test_suite = TestParser::RSpec.find_tests!(path_for_test_project)
|
11
|
+
@test_names = @test_suite.map(&:identification)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'finds all the test_suite' do
|
15
|
+
@test_suite.should have(2).test_suite
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'finds nested test_suite' do
|
19
|
+
@test_names.should include('Life/with death sentence/should(be_alive)')
|
20
|
+
test = @test_suite[@test_names.index('Life/with death sentence/should(be_alive)')]
|
21
|
+
test.file.should == (path_for_test_project('spec/example_spec.rb')).to_s
|
22
|
+
test.extras[:line_number].should == 11
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'finds not nested test_suite' do
|
26
|
+
@test_names.should include('Life/actually lives')
|
27
|
+
test = @test_suite[@test_names.index('Life/actually lives')]
|
28
|
+
|
29
|
+
test.file.should == (path_for_test_project('spec/example_spec.rb')).to_s
|
30
|
+
test.extras[:line_number].should == 5
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'test_parser/source_code'
|
3
|
+
|
4
|
+
describe TestParser::SourceCode do
|
5
|
+
include FakeFS::SpecHelpers
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
File.open('standard_class_source.rb', 'w') do |f|
|
9
|
+
f << standard_class_source
|
10
|
+
end
|
11
|
+
File.open('dsl_source.rb', 'w') do |f|
|
12
|
+
f << dsl_source
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
after(:each) do
|
17
|
+
TestParser::SourceCode.clear_cache
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has the sexp of the original file' do
|
21
|
+
sexp = RubyParser.new.parse standard_class_source
|
22
|
+
TestParser::SourceCode.for('standard_class_source.rb').sexp.should == sexp
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.extract_method' do
|
26
|
+
it 'finds the method definition from the method name' do
|
27
|
+
snippet = TestParser::SourceCode.for('standard_class_source.rb').extract_method('method')
|
28
|
+
snippet.to_code.should match_code(<<-METHOD)
|
29
|
+
def method(some)
|
30
|
+
puts some
|
31
|
+
end
|
32
|
+
METHOD
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '.extract_code_from_line' do
|
37
|
+
it 'finds the line with its block' do
|
38
|
+
snippet = TestParser::SourceCode.for('dsl_source.rb').extract_code_from_line(2)
|
39
|
+
snippet.to_code.should match_code(<<-METHOD)
|
40
|
+
method 'ble' do
|
41
|
+
testing_something
|
42
|
+
end
|
43
|
+
METHOD
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def standard_class_source
|
48
|
+
<<-SOURCE
|
49
|
+
class A
|
50
|
+
def method(some)
|
51
|
+
puts some
|
52
|
+
end
|
53
|
+
end
|
54
|
+
SOURCE
|
55
|
+
end
|
56
|
+
|
57
|
+
def dsl_source
|
58
|
+
<<-SOURCE
|
59
|
+
calling :something do
|
60
|
+
method 'ble' do
|
61
|
+
testing_something
|
62
|
+
end
|
63
|
+
end
|
64
|
+
SOURCE
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
Bundler.require :default, :test
|
4
|
+
|
5
|
+
Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each {|f| require f }
|
6
|
+
|
7
|
+
require 'fakefs/spec_helpers'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.include ProjectsPaths
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
RSpec::Matchers.define :match_code do |expected|
|
2
|
+
expected_sexp = RubyParser.new.parse(expected)
|
3
|
+
|
4
|
+
match do |actual|
|
5
|
+
actual_sexp = actual.sexp if actual.respond_to? :sexp
|
6
|
+
actual_sexp ||= RubyParser.new.parse(actual)
|
7
|
+
expected_sexp == actual_sexp
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module ProjectsPaths
|
4
|
+
|
5
|
+
def devotest_path
|
6
|
+
Pathname.new File.join(File.dirname(__FILE__), '..', '..')
|
7
|
+
end
|
8
|
+
|
9
|
+
def path_for_test_project(*append)
|
10
|
+
([devotest_path, 'test_project'] + append).reduce(:+).cleanpath
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'test_parser'
|
4
|
+
|
5
|
+
describe TestParser do
|
6
|
+
|
7
|
+
describe ".minitest_tests" do
|
8
|
+
it 'delegates test finding to TestParser::MiniTest' do
|
9
|
+
TestParser::MiniTest.should_receive(:find_tests!).
|
10
|
+
with(path_for_test_project, {}).and_return []
|
11
|
+
|
12
|
+
TestParser.minitest_tests(path_for_test_project)
|
13
|
+
end
|
14
|
+
it 'passes extra options to TestParser::Minitest' do
|
15
|
+
TestParser::MiniTest.should_receive(:find_tests!).
|
16
|
+
with(path_for_test_project, {:some_option => true}).and_return []
|
17
|
+
|
18
|
+
TestParser.minitest_tests(path_for_test_project, {:some_option => true})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".rspec_tests" do
|
23
|
+
it 'delegates test finding to TestParser::RSpec' do
|
24
|
+
TestParser::RSpec.should_receive(:find_tests!).
|
25
|
+
with(path_for_test_project, {}).and_return []
|
26
|
+
|
27
|
+
TestParser.rspec_tests(path_for_test_project)
|
28
|
+
end
|
29
|
+
it 'passes extra options to TestParser::RSpec' do
|
30
|
+
TestParser::RSpec.should_receive(:find_tests!).
|
31
|
+
with(path_for_test_project, {:some_option => true}).and_return []
|
32
|
+
|
33
|
+
TestParser.rspec_tests(path_for_test_project, {:some_option => true})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe ".all_tests" do
|
38
|
+
it "collects all the test from the default frameworks" do
|
39
|
+
stub_frameworks
|
40
|
+
|
41
|
+
tests = TestParser.all_tests(path_for_test_project)
|
42
|
+
tests.should == [:rspec, :minitest]
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when :frameworks are specified" do
|
46
|
+
it 'collects only for the given frameworks' do
|
47
|
+
stub_frameworks
|
48
|
+
|
49
|
+
options = {:frameworks => [:rspec]}
|
50
|
+
tests = TestParser.all_tests(path_for_test_project, options)
|
51
|
+
tests.should == [:rspec]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def stub_frameworks
|
56
|
+
TestParser::RSpec.stub(:find_tests!) { [:rspec]}
|
57
|
+
TestParser::MiniTest.stub(:find_tests!) {[:minitest]}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/test/rspec_test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup
|
5
|
+
Bundler.require :default
|
6
|
+
|
7
|
+
require_relative '../spec/support/projects_paths'
|
8
|
+
require 'test_parser'
|
9
|
+
|
10
|
+
# This test is only to check there isn't any side effect for testing with Rspec
|
11
|
+
# while parsing RSpec specs.
|
12
|
+
class RSpecTest < MiniTest::Unit::TestCase
|
13
|
+
|
14
|
+
include ProjectsPaths
|
15
|
+
|
16
|
+
def test_rspec_parsing
|
17
|
+
tests = TestParser::RSpec.find_tests!(path_for_test_project)
|
18
|
+
test = tests.first
|
19
|
+
assert_equal 'Life/actually lives', test.identification
|
20
|
+
assert_equal path_for_test_project('spec/example_spec.rb').to_s, test.file
|
21
|
+
assert_equal 5, test.extras[:line_number]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/test_parser.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "test_parser/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "test_parser"
|
7
|
+
s.version = TestParser::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Juan Manuel Barreneche"]
|
10
|
+
s.email = ["juanmanuel.barreneche@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Retrieves information of your test suite}
|
13
|
+
s.description = %q{Retrieves information of your test suite}
|
14
|
+
|
15
|
+
s.rubyforge_project = "test_parser"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'ruby_parser', '~> 2.0.5'
|
23
|
+
s.add_dependency 'ruby2ruby', '~> 1.2.5'
|
24
|
+
s.add_dependency 'rspec-core', '~> 2.5.0'
|
25
|
+
s.add_dependency 'minitest', '~> 2.0.2'
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.pattern = "test/**/*_test.rb"
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new
|
13
|
+
|
14
|
+
task :default => [:test, :spec]
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative '../life'
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Juan Manuel Barreneche
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-20 00:00:00 -03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: ruby_parser
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.0.5
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby2ruby
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.2.5
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec-core
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.5.0
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: minitest
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 2.0.2
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id004
|
60
|
+
description: Retrieves information of your test suite
|
61
|
+
email:
|
62
|
+
- juanmanuel.barreneche@gmail.com
|
63
|
+
executables:
|
64
|
+
- test_parser
|
65
|
+
extensions: []
|
66
|
+
|
67
|
+
extra_rdoc_files: []
|
68
|
+
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- .rvmrc
|
72
|
+
- Gemfile
|
73
|
+
- Rakefile
|
74
|
+
- bin/test_parser
|
75
|
+
- lib/test_parser.rb
|
76
|
+
- lib/test_parser/common.rb
|
77
|
+
- lib/test_parser/extensions/minitest.rb
|
78
|
+
- lib/test_parser/extensions/rspec.rb
|
79
|
+
- lib/test_parser/minitest.rb
|
80
|
+
- lib/test_parser/rspec.rb
|
81
|
+
- lib/test_parser/snippet.rb
|
82
|
+
- lib/test_parser/source_code.rb
|
83
|
+
- lib/test_parser/test_information.rb
|
84
|
+
- lib/test_parser/version.rb
|
85
|
+
- spec/minitest_spec.rb
|
86
|
+
- spec/rspec_spec.rb
|
87
|
+
- spec/source_code_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- spec/support/matchers/match_code.rb
|
90
|
+
- spec/support/projects_paths.rb
|
91
|
+
- spec/test_parser_spec.rb
|
92
|
+
- test/rspec_test.rb
|
93
|
+
- test_parser.gemspec
|
94
|
+
- test_project/Rakefile
|
95
|
+
- test_project/life.rb
|
96
|
+
- test_project/spec/example_spec.rb
|
97
|
+
- test_project/spec/spec_helper.rb
|
98
|
+
- test_project/test/example_test.rb
|
99
|
+
- test_project/test/test_helper.rb
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: ""
|
102
|
+
licenses: []
|
103
|
+
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: "0"
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: "0"
|
121
|
+
requirements: []
|
122
|
+
|
123
|
+
rubyforge_project: test_parser
|
124
|
+
rubygems_version: 1.5.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: Retrieves information of your test suite
|
128
|
+
test_files:
|
129
|
+
- spec/minitest_spec.rb
|
130
|
+
- spec/rspec_spec.rb
|
131
|
+
- spec/source_code_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/support/matchers/match_code.rb
|
134
|
+
- spec/support/projects_paths.rb
|
135
|
+
- spec/test_parser_spec.rb
|
136
|
+
- test/rspec_test.rb
|