Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window command line generation patches #762

Merged
merged 3 commits into from
Dec 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/autotest/rspec2.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def consolidate_failures(failed)
# Overrides Autotest's implementation to generate the rspec command to run # Overrides Autotest's implementation to generate the rspec command to run
def make_test_cmd(files_to_test) def make_test_cmd(files_to_test)
files_to_test.empty? ? '' : files_to_test.empty? ? '' :
"#{prefix}'#{ruby}'#{suffix} -S '#{RSPEC_EXECUTABLE}' --tty #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}" %|#{prefix}"#{ruby}"#{suffix} -S "#{RSPEC_EXECUTABLE}" --tty #{normalize(files_to_test).keys.flatten.map { |f| %|"#{f}"|}.join(' ')}|
end end


# Generates a map of filenames to Arrays for Autotest # Generates a map of filenames to Arrays for Autotest
Expand Down
12 changes: 9 additions & 3 deletions spec/autotest/rspec_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@
@to_test = files.map { |f| File.expand_path(f) }.join ' ' @to_test = files.map { |f| File.expand_path(f) }.join ' '
end end


it "uses double quotes for windows compatibility" do
command = rspec_autotest.make_test_cmd(@files_to_test)
command.should include('"')
command.should_not include("'")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be expressed in a simpler fashion:

command = rspec_autotest.make_test_cmd(@files_to_test)
command.should include('"')
command.should_not include("'")

The regex seems more convoluted and doesn't actually verify that double quotes are included....which seems kinda important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, proper use of matches is key to expressiveness and when you see people not exploiting the full vocabulary of your test framework it only indicates one thing; lack of insight :)

My reasoning for not checking for double quotes was that I was thinking a bit non-TDD, namely "what if he decided in the future to no longer need quoting, then the test would break at that point", instead of the proper notion: "how is the code supposed to work NOW". I'll remedy it as suggested.


it "makes the appropriate test command" do it "makes the appropriate test command" do
actual_command = rspec_autotest.make_test_cmd(@files_to_test) actual_command = rspec_autotest.make_test_cmd(@files_to_test)
expected_command = /#{ruby_cmd}.*'#{spec_cmd}' (.*)/ expected_command = /#{ruby_cmd}.*"#{spec_cmd}" (.*)/


actual_command.should match(expected_command) actual_command.should match(expected_command)


Expand All @@ -46,13 +52,13 @@
it "quotes the paths of files to test" do it "quotes the paths of files to test" do
cmd = rspec_autotest.make_test_cmd(@files_to_test) cmd = rspec_autotest.make_test_cmd(@files_to_test)
@files_to_test.keys.each do |file_to_test| @files_to_test.keys.each do |file_to_test|
cmd.should match(/'#{File.expand_path(file_to_test)}'/) cmd.should match(/"#{File.expand_path(file_to_test)}"/)
end end
end end


it "quotes the path of the ruby executable" do it "quotes the path of the ruby executable" do
cmd = rspec_autotest.make_test_cmd(@files_to_test) cmd = rspec_autotest.make_test_cmd(@files_to_test)
cmd.should match(%r('/path/to/ruby')) cmd.should match(%r("/path/to/ruby"))
end end


it "gives '--tty' to #{Autotest::Rspec2::RSPEC_EXECUTABLE}, not '--autotest'" do it "gives '--tty' to #{Autotest::Rspec2::RSPEC_EXECUTABLE}, not '--autotest'" do
Expand Down