Skip to content

Commit

Permalink
Refactored Ctags class.
Browse files Browse the repository at this point in the history
  • Loading branch information
rejeep committed Aug 21, 2010
1 parent af58ee5 commit e82a340
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
24 changes: 12 additions & 12 deletions lib/mactag/ctags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ def initialize(input, output)
end

def create
system(command)
end


private

def command
"cd #{Rails.root} && #{binary}"
end

def binary
binary = Mactag::Config.binary

binary.gsub!('{OUTPUT}', @output)
binary.gsub!('{INPUT}', @input.join(' '))

exec(binary)
end


private

def exec(binary)
system command(binary)
end

def command(binary)
"cd #{Rails.root} && #{binary}"
binary
end
end
end
35 changes: 19 additions & 16 deletions spec/mactag/ctags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@

describe Mactag::Ctags do
before do
Mactag::Config.stub!(:binary).and_return('ctags -o {OUTPUT} -e {INPUT}')

@ctags = Mactag::Ctags.new('in', 'out')
@ctags.stub!(:exec)
end

describe '#create' do
it 'should execute command' do
@ctags.should_receive(:exec).with('ctags -o out -e in')
@ctags.create
describe '#initialize' do
it 'should handle single file' do
@ctags = Mactag::Ctags.new('in', 'out')
@ctags.instance_variable_get('@input').should =~ ['in']
end

it 'should handle multiple files' do
@ctags = Mactag::Ctags.new(['in_1', 'in_2'], 'out')
@ctags.instance_variable_get('@input').should =~ ['in_1', 'in_2']
end
end

describe '#command' do
it 'should return the correct command' do
before do
Rails.stub!(:root).and_return('root')
@ctags.stub!(:binary).and_return('binary')
end

@ctags.send(:command, 'bin').should == 'cd root && bin'
it 'should return correct command' do
@ctags.send(:command).should == 'cd root && binary'
end
end

context 'input files' do
it 'should handle single file' do
@ctags = Mactag::Ctags.new('in', 'out')
@ctags.instance_variable_get('@input').should =~ ['in']
describe '#binary' do
before do
Mactag::Config.stub!(:binary).and_return('ctags -o {OUTPUT} -e {INPUT}')
end

it 'should handle multiple files' do
@ctags = Mactag::Ctags.new(['in_1', 'in_2'], 'out')
@ctags.instance_variable_get('@input').should =~ ['in_1', 'in_2']
it 'should return correct command' do
@ctags.send(:binary).should == 'ctags -o out -e in'
end
end
end

0 comments on commit e82a340

Please sign in to comment.