Skip to content

Instantly share code, notes, and snippets.

@janmejay
Created December 12, 2010 01:39
Show Gist options
  • Save janmejay/737778 to your computer and use it in GitHub Desktop.
Save janmejay/737778 to your computer and use it in GitHub Desktop.
From 52859e4f013512157ab86cea4e89df5b651af88d Mon Sep 17 00:00:00 2001
From: Janmejay Singh <[email protected]>
Date: Tue, 14 Dec 2010 20:37:51 +0530
Subject: [PATCH] rake_task now capable of loading specs with single and double quotes in path
---
lib/rspec/core/rake_task.rb | 2 +-
spec/rspec/core/rake_task_spec.rb | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/lib/rspec/core/rake_task.rb b/lib/rspec/core/rake_task.rb
index ad2da9d..0d576b2 100644
--- a/lib/rspec/core/rake_task.rb
+++ b/lib/rspec/core/rake_task.rb
@@ -149,7 +149,7 @@ module RSpec
if ENV['SPEC']
FileList[ ENV['SPEC'] ]
else
- FileList[ pattern ].map { |f| %["#{f}"] }
+ FileList[ pattern ].map { |f| f.gsub(/"/, '\"').gsub(/'/, "\\\\'") }
end
end
diff --git a/spec/rspec/core/rake_task_spec.rb b/spec/rspec/core/rake_task_spec.rb
index 97d9f66..e240a40 100644
--- a/spec/rspec/core/rake_task_spec.rb
+++ b/spec/rspec/core/rake_task_spec.rb
@@ -136,5 +136,37 @@ module RSpec::Core
task.__send__(:files_to_run).should eq(["path/to/file"])
end
end
+
+ context "with pattern matching files with quotes" do
+ before do
+ @tmp_dir = File.expand_path(File.join(File.dirname(__FILE__), "rake_task_tmp_dir"))
+ @task = RakeTask.new do |t|
+ t.pattern = File.join(@tmp_dir, "*.rb")
+ end
+ FileUtils.mkdir_p @tmp_dir
+ spec_file_content = <<-END
+describe "spec" do
+ it "should pass" do
+ 1.should == 1
+ end
+end
+END
+ ["first_file.rb", "second_\"file.rb", "third_'file.rb"].each do |file_name|
+ File.open(File.join(@tmp_dir, file_name), "w") do |h|
+ h.write spec_file_content
+ end
+ end
+ end
+
+ after do
+ FileUtils.rm_rf @tmp_dir
+ end
+
+ it "sets files to run" do
+ `/usr/bin/env ruby #{@task.send(:spec_command)}`
+ $?.exitstatus.should == 0
+ #@task.send(:files_to_run).should eq([])
+ end
+ end
end
end
--
1.7.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment