From 500ec9a8b64b193ae02b8f655928effbd35a0c2e Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Tue, 26 Jan 2010 01:19:09 -0600 Subject: [PATCH] support line number appended to path --- .../command_line/line_number_option.feature | 56 ------------------- .../line_number_appended_to_path.feature | 39 +++++++++++++ lib/rspec/core/configuration.rb | 5 +- spec/rspec/core/configuration_spec.rb | 9 +++ 4 files changed, 52 insertions(+), 57 deletions(-) delete mode 100644 features-pending/command_line/line_number_option.feature create mode 100644 features/command_line/line_number_appended_to_path.feature diff --git a/features-pending/command_line/line_number_option.feature b/features-pending/command_line/line_number_option.feature deleted file mode 100644 index 4e9c2287e8..0000000000 --- a/features-pending/command_line/line_number_option.feature +++ /dev/null @@ -1,56 +0,0 @@ -Feature: Spec and test together - - As an RSpec user - I want to run one example identified by the line number - - Background: - Given a file named "example.rb" with: - """ - describe "a group" do - - it "has a first example" do - - end - - it "has a second example" do - - end - - end - """ - - Scenario: two examples - first example on declaration line - When I run "spec example.rb:3 --format nested" - Then the stdout should match "1 example, 0 failures" - And the stdout should match "has a first example" - But the stdout should not match "has a second example" - - Scenario: two examples - first example from line inside declaration - When I run "spec example.rb:4 --format nested" - Then the stdout should match "1 example, 0 failures" - And the stdout should match "has a first example" - But the stdout should not match "has a second example" - - Scenario: two examples - first example from line below declaration - When I run "spec example.rb:6 --format nested" - Then the stdout should match "1 example, 0 failures" - And the stdout should match "has a first example" - But the stdout should not match "has a second example" - - Scenario: two examples - second example from line below declaration - When I run "spec example.rb:7 --format nested" - Then the stdout should match "1 example, 0 failures" - And the stdout should match "has a second example" - But the stdout should not match "has a first example" - - Scenario: two examples - both examples from the group declaration - When I run "spec example.rb:1 --format nested" - Then the stdout should match "2 examples, 0 failures" - And the stdout should match "has a second example" - And the stdout should match "has a first example" - - Scenario: two examples - both examples from above the first example declaration - When I run "spec example.rb:2 --format nested" - Then the stdout should match "2 examples, 0 failures" - And the stdout should match "has a second example" - And the stdout should match "has a first example" diff --git a/features/command_line/line_number_appended_to_path.feature b/features/command_line/line_number_appended_to_path.feature new file mode 100644 index 0000000000..bf16d16b51 --- /dev/null +++ b/features/command_line/line_number_appended_to_path.feature @@ -0,0 +1,39 @@ +Feature: line number appended to file path + + As an RSpec user + I want to run one example identified by the + line number appended to the filepath + + Background: + Given a file named "example_spec.rb" with: + """ + describe "a group" do + + it "has a first example" do + + end + + it "has a second example" do + + end + + end + """ + + Scenario: two examples - both examples from the group declaration + When I run "spec example_spec.rb:1 --format doc" + Then the stdout should match "2 examples, 0 failures" + And the stdout should match "has a second example" + And the stdout should match "has a first example" + + Scenario: two examples - first example on declaration line + When I run "spec example_spec.rb:3 --format doc" + Then the stdout should match "1 example, 0 failures" + And the stdout should match "has a first example" + But the stdout should not match "has a second example" + + Scenario: two examples - second example on declaration line + When I run "spec example_spec.rb:7 --format doc" + Then the stdout should match "1 example, 0 failures" + And the stdout should match "has a second example" + But the stdout should not match "has a first example" diff --git a/lib/rspec/core/configuration.rb b/lib/rspec/core/configuration.rb index 4a992de641..2480b5dd7c 100644 --- a/lib/rspec/core/configuration.rb +++ b/lib/rspec/core/configuration.rb @@ -137,13 +137,16 @@ def files_to_run end def files_or_directories_to_run=(*files) + p files options[:files_to_run] = files.flatten.inject([]) do |result, file| if File.directory?(file) filename_pattern.split(",").each do |pattern| result += Dir[File.expand_path("#{file}/#{pattern.strip}")] end else - result << file + file =~ /([^:]*):?(\d+)?/ + self.line_number = $2 if $2 + result << $1 end result end diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index 50447b9ffd..f5485eadb6 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -102,6 +102,15 @@ end + context "with line number" do + + it "assigns the line number as the filter" do + @config.files_or_directories_to_run = "path/to/a_spec.rb:37" + @config.filter.should == {:line_number => 37} + end + + end + end describe "include" do