Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rename spec parser to line number query

  • Loading branch information...
commit 41165507d222aeeff482aad13a8f4c8c75402a8a 1 parent 1fc52ea
@dchelimsky authored
View
2  lib/spec/example/example_group_methods.rb
@@ -226,7 +226,7 @@ def run_after_all(success, instance_variables, run_options)
def examples_to_run(run_options)
return example_proxies unless examples_were_specified?(run_options)
if run_options.line_number
- line = Spec::Runner::SpecParser.new(run_options).example_line_for(run_options.files.first, run_options.line_number)
+ line = Spec::Runner::LineNumberQuery.new(run_options).example_line_for(run_options.files.first, run_options.line_number)
result = example_proxies.select {|proxy| proxy.location =~ /:#{line}$/}
result.empty? ? example_proxies : result
else
View
2  lib/spec/runner.rb
@@ -6,7 +6,7 @@
require 'spec/runner/drb_command_line'
require 'spec/runner/backtrace_tweaker'
require 'spec/runner/reporter'
-require 'spec/runner/spec_parser'
+require 'spec/runner/line_number_query'
require 'spec/runner/class_and_arguments_parser'
require 'spec/runner/extensions/kernel'
View
21 lib/spec/runner/spec_parser.rb → lib/spec/runner/line_number_query.rb
@@ -1,7 +1,7 @@
module Spec
module Runner
# Parses a spec file and finds the nearest example for a given line number.
- class SpecParser
+ class LineNumberQuery
attr_reader :best_match
def initialize(run_options)
@@ -12,14 +12,7 @@ def initialize(run_options)
def spec_name_for(file, line_number)
best_match.clear
file = File.expand_path(file)
- @run_options.example_groups.each do |example_group|
- next unless example_group.location
- consider_example_group_for_best_match(example_group, file, line_number)
-
- example_group.examples.each do |example|
- consider_example_for_best_match(example, example_group, file, line_number)
- end
- end
+ determine_best_match(file, line_number)
if best_match[:example_group]
if best_match[:example]
"#{best_match[:example_group].description} #{best_match[:example].description}"
@@ -32,6 +25,13 @@ def spec_name_for(file, line_number)
end
def example_line_for(file, line_number)
+ determine_best_match(file, line_number)
+ best_match[:line]
+ end
+
+ protected
+
+ def determine_best_match(file, line_number)
best_match.clear
file = File.expand_path(file)
@run_options.example_groups.each do |example_group|
@@ -42,10 +42,7 @@ def example_line_for(file, line_number)
consider_example_for_best_match(example, example_group, file, line_number)
end
end
- best_match[:line]
end
-
- protected
def consider_example_group_for_best_match(example_group, file, line_number)
example_group_file, example_group_line = parse_location(example_group.location)
View
2  lib/spec/runner/options.rb
@@ -340,7 +340,7 @@ def set_spec_from_line_number
error_stream.puts "You must specify one file, not a directory when providing a line number"
exit(1) if stderr?
else
- example = SpecParser.new(self).spec_name_for(files[0], line_number)
+ example = LineNumberQuery.new(self).spec_name_for(files[0], line_number)
@examples = [example]
end
else
View
8 ...runner/spec_parser/spec_parser_fixture.rb → ...number_query/line_number_query_fixture.rb
@@ -20,24 +20,24 @@
end
-class SpecParserSubject
+class LineNumberQuerySubject
end
-describe SpecParserSubject do
+describe LineNumberQuerySubject do
it "5" do
end
end
-describe SpecParserSubject, "described" do
+describe LineNumberQuerySubject, "described" do
it "6" do
end
end
-describe SpecParserSubject, "described", :something => :something_else do
+describe LineNumberQuerySubject, "described", :something => :something_else do
it "7" do
end
View
20 spec/spec/runner/spec_parser_spec.rb → spec/spec/runner/line_number_query_spec.rb
@@ -1,12 +1,12 @@
require File.dirname(__FILE__) + '/../../spec_helper.rb'
-describe "SpecParser" do
+describe "LineNumberQuery" do
with_sandboxed_options do
attr_reader :parser, :file
before do
- @parser = Spec::Runner::SpecParser.new(options)
- @file = "#{File.dirname(__FILE__)}/spec_parser/spec_parser_fixture.rb"
+ @parser = Spec::Runner::LineNumberQuery.new(options)
+ @file = "#{File.dirname(__FILE__)}/line_number_query/line_number_query_fixture.rb"
load file
end
@@ -43,27 +43,27 @@
end
it "should find context name for type" do
- parser.spec_name_for(file, 26).should == "SpecParserSubject"
+ parser.spec_name_for(file, 26).should == "LineNumberQuerySubject"
end
it "should find context and spec name for type" do
- parser.spec_name_for(file, 28).should == "SpecParserSubject 5"
+ parser.spec_name_for(file, 28).should == "LineNumberQuerySubject 5"
end
it "should find context and description for type" do
- parser.spec_name_for(file, 33).should == "SpecParserSubject described"
+ parser.spec_name_for(file, 33).should == "LineNumberQuerySubject described"
end
it "should find context and description and example for type" do
- parser.spec_name_for(file, 36).should == "SpecParserSubject described 6"
+ parser.spec_name_for(file, 36).should == "LineNumberQuerySubject described 6"
end
it "should find context and description for type with modifications" do
- parser.spec_name_for(file, 40).should == "SpecParserSubject described"
+ parser.spec_name_for(file, 40).should == "LineNumberQuerySubject described"
end
it "should find context and described and example for type with modifications" do
- parser.spec_name_for(file, 43).should == "SpecParserSubject described 7"
+ parser.spec_name_for(file, 43).should == "LineNumberQuerySubject described 7"
end
it "should find example group" do
@@ -91,7 +91,7 @@
options = stub('options', :example_groups => [
stub('example_group', :location => nil)
])
- parser = Spec::Runner::SpecParser.new(options)
+ parser = Spec::Runner::LineNumberQuery.new(options)
parser.spec_name_for('foo',37).should == nil
end
View
2  spec/spec/runner/option_parser_spec.rb
@@ -267,7 +267,7 @@ def parse(args)
attr_reader :file, :dir
before(:each) do
@original_rspec_options = Spec::Runner.options
- @file = "#{File.dirname(__FILE__)}/spec_parser/spec_parser_fixture.rb"
+ @file = "#{File.dirname(__FILE__)}/line_number_query/line_number_query_fixture.rb"
@dir = File.dirname(file)
end
Please sign in to comment.
Something went wrong with that request. Please try again.