Skip to content

Commit

Permalink
Refactor static_library_task.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Oct 12, 2013
1 parent bf3c87c commit 8b5b095
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 32 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.0
7 changes: 5 additions & 2 deletions lib/paper_house/library_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ module PaperHouse
# Common base class for static, shared, and ruby library tasks.
class LibraryTask < BuildTask
# Find a LibraryTask by name
def self.find_by name
def self.find_named name
ObjectSpace.each_object( self ) do | each |
return each if each.name == name.to_s
obj_name = each.name
if Rake::Task.task_defined?( obj_name ) and obj_name == name.to_s
return each
end
end
nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/paper_house/linker_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def find_prerequisites task, klass_list


def maybe_enhance name, klass
task = klass.find_by( name )
task = klass.find_named( name )
enhance task if task
end

Expand Down
6 changes: 3 additions & 3 deletions spec/paper_house/shared_library_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module PaperHouse
it "should find registered tasks by name" do
task = SharedLibraryTask.new( :libtest, "0.1.0" )

SharedLibraryTask.find_by( :libtest ).should eq task
SharedLibraryTask.find_by( "libtest" ).should eq task
SharedLibraryTask.find_by( :no_such_task ).should be_nil
SharedLibraryTask.find_named( :libtest ).should eq task
SharedLibraryTask.find_named( "libtest" ).should eq task
SharedLibraryTask.find_named( :no_such_task ).should be_nil
end
end

Expand Down
101 changes: 75 additions & 26 deletions spec/paper_house/static_library_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,90 @@
require "paper_house/static_library_task"


describe "Rake::Task" do
before { Rake::Task.clear }

describe ".[]" do
subject { Rake::Task[ task ] }

context "with :libtest" do
let( :task ) { :libtest }

context "when StaticLibraryTask named :libtest is defined" do
before { PaperHouse::StaticLibraryTask.new :libtest }

describe "#invoke" do
it { expect { subject.invoke }.to raise_error( "Cannot find sources (*.c)." ) }
end
end

context "when StaticLibraryTask named :libtest is not defined" do
it { expect { subject }.to raise_error }
end
end
end
end


module PaperHouse
describe StaticLibraryTask do
it "should find registered tasks by name" do
task = StaticLibraryTask.new( :libtest )
before { Rake::Task.clear }

describe ".find_named" do
subject { StaticLibraryTask.find_named name }

context "with :libtest" do
let( :name ) { :libtest }

StaticLibraryTask.find_by( :libtest ).should eq task
StaticLibraryTask.find_by( "libtest" ).should eq task
StaticLibraryTask.find_by( :no_such_task ).should be_nil
context "when StaticLibraryTask named :libtest is defined" do
before { StaticLibraryTask.new :libtest }

it { expect( subject ).to be_a StaticLibraryTask }
end

context "when StaticLibraryTask named :libtest is not defined" do
it { expect( subject ).to be_nil }
end
end

context %{with "libtest"} do
context "when StaticLibraryTask named :libtest is defined" do
before { StaticLibraryTask.new :libtest }
let( :name ) { "libtest" }

it { expect( subject ).to be_a StaticLibraryTask }
end
end

context "with :NO_SUCH_TASK" do
let( :name ) { :NO_SUCH_TASK }

it { expect( subject ).to be_nil }
end
end
end


describe StaticLibraryTask, ".new( :libtest )" do
subject { StaticLibraryTask.new :libtest }

its( :cc ) { should eq "gcc" }
its( :cflags ) { should be_empty }
its( :includes ) { should be_empty }
its( :name ) { should eq "libtest" }
its( :sources ) { should eq "*.c" }
its( :target_directory ) { should eq "." }
its( :library_name ) { should eq "libtest" }
its( :lname ) { should eq "test" }
its( :target_file_name ) { should eq "libtest.a" }
its( :target_path ) { should eq "./libtest.a" }

it {
expect {
Rake::Task[ subject.name ].invoke
}.to raise_error( "Cannot find sources (*.c)." )
}
describe ".new" do
subject { StaticLibraryTask.new task }

context "with :libtest" do
let( :task ) { :libtest }

its( :cc ) { should eq "gcc" }
its( :cflags ) { should be_empty }
its( :includes ) { should be_empty }
its( :name ) { should eq "libtest" }
its( :sources ) { should eq "*.c" }
its( :target_directory ) { should eq "." }
its( :library_name ) { should eq "libtest" }
its( :lname ) { should eq "test" }
its( :target_file_name ) { should eq "libtest.a" }
its( :target_path ) { should eq "./libtest.a" }
end
end
end
end


### Local variables:
### mode: Ruby
### coding: utf-8-unix
Expand Down

0 comments on commit 8b5b095

Please sign in to comment.