Skip to content

Commit

Permalink
Make 'Alternate File' Merb-aware [#582 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Moran authored and dchelimsky committed Oct 26, 2008
1 parent fbdb1ba commit 087b48a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 10 additions & 2 deletions Support/lib/spec/mate/switch_command.rb
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions Support/spec/spec/mate/switch_command_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 087b48a

Please sign in to comment.