diff --git a/Support/lib/spec/mate/switch_command.rb b/Support/lib/spec/mate/switch_command.rb index 13ba5be13..96126a27e 100644 --- a/Support/lib/spec/mate/switch_command.rb +++ b/Support/lib/spec/mate/switch_command.rb @@ -23,7 +23,7 @@ def twin(path) case parent when 'lib', 'app' then - if rails?(prefix) + if webapp?(prefix) path = path.gsub(/\/app\//, "/spec/") path = path.gsub(/\/lib\//, "/spec/lib/") path = path.gsub(/application\.rb/, 'application_controller.rb') @@ -37,7 +37,7 @@ def twin(path) path = path.gsub(/\.rhtml_spec\.rb$/, ".rhtml") path = path.gsub(/\.erb_spec\.rb$/, ".erb") path = path.gsub(/_spec\.rb$/, ".rb") - if rails?(prefix) + if webapp?(prefix) path = path.gsub(/\/spec\/lib\//, "/lib/") path = path.gsub(/\/spec\//, "/app/") path = path.gsub(/application_controller\.rb/, 'application.rb') @@ -62,10 +62,18 @@ def file_type(path) "file" end + def webapp?(prefix) + rails?(prefix) || merb?(prefix) + end + def rails?(prefix) File.exist?(File.join(prefix, 'config', 'boot.rb')) end + def merb?(prefix) + File.exist?(File.join(prefix, 'config', 'init.rb')) + end + def create?(relative_twin, file_type) answer = `#{ ENV['TM_SUPPORT_PATH'] }/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog yesno-msgbox --no-cancel --icon document --informative-text "#{relative_twin}" --text "Create missing #{file_type}?"` answer.to_s.chomp == "1" diff --git a/Support/spec/spec/mate/switch_command_spec.rb b/Support/spec/spec/mate/switch_command_spec.rb index 72019d3dd..3450e42e1 100644 --- a/Support/spec/spec/mate/switch_command_spec.rb +++ b/Support/spec/spec/mate/switch_command_spec.rb @@ -3,16 +3,16 @@ module Spec module Mate class Twin - def initialize(expected, rails) + def initialize(expected, webapp) @expected = expected - @rails = rails + @webapp = webapp end def matches?(actual) @actual = actual # Satisfy expectation here. Return false or raise an error if it's not met. command = SwitchCommand.new - command.stub!(:rails?).and_return(@rails) + command.stub!(:webapp?).and_return(@webapp) path = command.twin(@actual) path.should == @expected @@ -43,7 +43,7 @@ def initialize(expected) def matches?(actual) @actual = actual c = SwitchCommand.new - c.stub!(:rails?).and_return(@rails) + c.stub!(:webapp?).and_return(@webapp) c.file_type(@actual).should == @expected true end @@ -167,7 +167,7 @@ def twin(expected) "/a/full/path/spec/views/mooky/show.rhtml_spec.rb") end - it "should work with lib dir in rails" do + it "should work with lib dir in rails or merb" do "/a/full/path/lib/foo/mooky.rb".should twin( "/a/full/path/spec/lib/foo/mooky_spec.rb") end