Skip to content

Commit

Permalink
Fix failing unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Jolley committed Nov 17, 2009
1 parent 013c2fa commit 6d6b3ce
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/sproutcore/models/manifest_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def timestamp
end
timestamps.max
elsif composite?
source_entries.map { |e| e.timestamp }.max

source_entries.map { |e| e.timestamp || 0 }.max || Time.now.to_i
else
File.exist?(source_path) ? File.mtime(source_path).to_i : 0
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sproutcore/models/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def _write_file_attr_cache
# if the mtime matches, the cached value is returned. otherwise, yields
# to the passed block to compute again.
def file_attr(attr_name, path, &block)

# read cache from disk if needed
if @file_attr_cache.nil?
if File.exists?(file_attr_cache_path)
Expand Down
5 changes: 5 additions & 0 deletions lib/sproutcore/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def project=(a_project)
@project = a_project
end

def set_test_project(a_project)
@project = a_project
@discovered_project = true
end

# The current project. This is discovered based on the passed --project
# option or based on the current working directory. If no project can
# be found, this method will always return null.
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/models/target/compute_build_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def add_dummyfile(project)
describe "accurate method to compute build number" do

before do
@target = @project.target_for(:sproutcore)
@target = @project.target_for(:sproutcore).prepare!
@target.config.build_numbers = nil #precondition
@target.config.build_number = nil #precondition
end
Expand All @@ -72,10 +72,10 @@ def add_dummyfile(project)
end

it "changes generated build number if build number for a required target changes" do
target = @project.target_for(:sproutcore)
target = @project.target_for(:sproutcore).prepare!
target.should_not be_nil

required = target.target_for(:desktop)
required = target.target_for(:desktop).prepare!
required.should_not be_nil
required.config.build_numbers = nil #precondition
required.config.build_number = nil #precondition
Expand All @@ -95,10 +95,10 @@ def add_dummyfile(project)
end

it "does not change generated build number if a nested target that is not required by target changes" do
target = @project.target_for(:sproutcore)
target = @project.target_for(:sproutcore).prepare!
target.should_not be_nil

not_required = target.target_for(:mobile)
not_required = target.target_for(:mobile).prepare!
not_required.should_not be_nil

#precondition
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/models/target/required_targets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
include SC::SpecHelpers

before do
@env = SC.build_mode # force debug mode
SC.build_mode = :debug

@project = fixture_project(:real_world)
end

after do
SC.build_mode = @env
end

it "should resolve references to child targets" do
target = @project.target_for :sproutcore
Expand Down Expand Up @@ -66,15 +73,18 @@
end

it "should log a warning if a required test or debug target could not be found" do

target = @project.target_for :sproutcore
target.config.test_required = 'imaginary_foo'
target.config.debug_required = 'imaginary_bar'

capture('stderr') { target.required_targets(:test => true) }.size.should_not == 0
capture('stderr') { target.required_targets(:debug => true) }.size.should_not == 0

end

it "should include any CONFIG.theme if passed :theme => true && target_type == :app" do

expected = @project.target_for 'sproutcore/standard_theme'

target = @project.target_for :contacts
Expand Down
13 changes: 10 additions & 3 deletions spec/lib/tools/build_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
include SC::SpecHelpers

before do
save_env
SC.build_mode = :production
@tool = SC::Tools.new('build_number')
end

after do
restore_env
end

it "should raise error if no target is passed" do
lambda { @tool.build_number }.should raise_error
end
Expand All @@ -17,11 +23,12 @@
end

it "should write build number when passed target" do
@tool.project = fixture_project(:real_world) # req...
bn = capture('stdout') { @tool.build_number('sproutcore') }

expected_target = fixture_project(:real_world).target_for(:sproutcore)
expected = expected_target.prepare!.compute_build_number

@tool.set_test_project fixture_project(:real_world) # req...
bn = capture('stdout') { @tool.build_number('sproutcore') }

bn.should eql(expected)
end

Expand Down
16 changes: 16 additions & 0 deletions spec/lib/tools/tools_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def dummy; end

describe "logger options" do

before do
save_env
end

after do
restore_env
end

it "should default to warn log level" do
SC::Tools.start %w(dummy)
SC.env.log_level.should == :warn
Expand Down Expand Up @@ -54,6 +62,14 @@ def dummy; end

describe "build mode options" do

before do
save_env
end

after do
restore_env
end

it "should default to :production build mode" do
SC::Tools.start %w(dummy)
SC.build_mode.should eql(:production)
Expand Down
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ def cleanup

module SpecHelpers

# env doesn't automatically reset
def save_env
@env ||= []
@env << { :env => SC.env.dup, :build_mode => SC.build_mode }
end

def restore_env
e = (@env || []).pop
SC.env = e[:env]
SC.build_mode = e[:build_mode]
end

def fixture_path(*path_items)
(path_items = path_items.flatten).unshift 'fixtures'
path_items.map! { |pi| pi.to_s }
Expand Down

0 comments on commit 6d6b3ce

Please sign in to comment.