Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove requirement of flexmock per Ruby bug #4987

  • Loading branch information...
commit 928e0a23b433f5fd3f197929d84f3c28d12b4e2c 1 parent 1bf0a8b
@drbrain drbrain authored
View
3  CHANGES
@@ -4,8 +4,9 @@
* The rake test loader now removes arguments it has processed. Issue #51
* Rake::TaskArguments now responds to #values_at
-* Rake tests are now directory-independent
* RakeFileUtils.verbose_flag = nil silences output the same as 0.8.7
+* Rake tests are now directory-independent
+* Rake tests are no longer require flexmock
== Version 0.9.2
View
1  Rakefile
@@ -183,7 +183,6 @@ else
s.required_rubygems_version = '>= 1.3.2'
s.add_development_dependency 'minitest', '~> 2.1'
s.add_development_dependency 'session', '~> 2.4'
- s.add_development_dependency 'flexmock', '~> 0.8.11'
#### Which files are to be included in this gem? Everything! (Except CVS directories.)
View
6 test/helper.rb
@@ -1,15 +1,11 @@
require 'rubygems'
require 'minitest/unit'
-require 'flexmock/test_unit_integration'
require 'minitest/autorun'
require 'rake'
require 'tmpdir'
require File.expand_path('../file_creation', __FILE__)
class Rake::TestCase < MiniTest::Unit::TestCase
- include FlexMock::ArgumentTypes
- include FlexMock::MockContainer
-
include FileCreation
include Rake::DSL
@@ -46,8 +42,6 @@ def setup
end
def teardown
- flexmock_teardown
-
Dir.chdir @orig_PWD
FileUtils.rm_rf @tempdir
View
43 test/test_rake_application.rb
@@ -232,7 +232,9 @@ def test_load_from_system_rakefile
def test_load_from_calculated_system_rakefile
rakefile_default
- flexmock(@app, :standard_system_dir => "__STD_SYS_DIR__")
+ def @app.standard_system_dir
+ "__STD_SYS_DIR__"
+ end
ENV['RAKE_SYSTEM'] = nil
@@ -270,25 +272,28 @@ def test_windows
end
def test_loading_imports
- mock = flexmock("loader")
- mock.should_receive(:load).with("x.dummy").once
+ loader = util_loader
+
@app.instance_eval do
- add_loader("dummy", mock)
+ add_loader("dummy", loader)
add_import("x.dummy")
load_imports
end
+
+ # HACK no assertions
end
def test_building_imported_files_on_demand
- mock = flexmock("loader")
- mock.should_receive(:load).with("x.dummy").once
- mock.should_receive(:make_dummy).with_no_args.once
+ loader = util_loader
+
@app.instance_eval do
- intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
- add_loader("dummy", mock)
+ intern(Rake::Task, "x.dummy").enhance do loader.make_dummy end
+ add_loader("dummy", loader)
add_import("x.dummy")
load_imports
end
+
+ # HACK no assertions
end
def test_handle_options_should_strip_options_from_ARGV
@@ -399,5 +404,25 @@ def test_deprecation_message
assert_match(/use 'b' instead/i, err)
assert_match(/at c$/i, err)
end
+
+ def util_loader
+ loader = Object.new
+
+ loader.instance_variable_set :@load_called, false
+ def loader.load arg
+ raise 'called more than once' if @load_called
+ raise ArgumentError, arg unless arg == 'x.dummy'
+ @load_called = true
+ end
+
+ loader.instance_variable_set :@make_dummy_called, false
+ def loader.make_dummy
+ raise 'called more than once' if @make_dummy_called
+ @make_dummy_called = true
+ end
+
+ loader
+ end
+
end
View
14 test/test_rake_task.rb
@@ -208,10 +208,7 @@ def test_timestamp_returns_now_if_all_prereqs_have_no_times
b = task :b
c = task :c
- faux_stamp = 100
- flexmock(Time, :now => faux_stamp)
-
- assert_equal faux_stamp, a.timestamp
+ assert_in_delta Time.now, a.timestamp, 0.1, 'computer too slow?'
end
def test_timestamp_returns_latest_prereq_timestamp
@@ -219,12 +216,11 @@ def test_timestamp_returns_latest_prereq_timestamp
b = task :b
c = task :c
- faux_stamp = 100
- flexmock(Time, :now => faux_stamp-10)
- flexmock(b, :timestamp => faux_stamp - 1)
- flexmock(c, :timestamp => faux_stamp)
+ now = Time.now
+ def b.timestamp() Time.now + 10 end
+ def c.timestamp() Time.now + 5 end
- assert_equal faux_stamp, a.timestamp
+ assert_in_delta now + 10, a.timestamp, 0.1, 'computer too slow?'
end
def test_investigation_output
View
31 test/test_rake_task_argument_parsing.rb
@@ -51,38 +51,31 @@ def test_terminal_width_using_env
end
def test_terminal_width_using_stty
- app = Rake::Application.new
-
- flexmock(app,
- :unix? => true,
- :dynamic_width_stty => 1235,
- :dynamic_width_tput => 0)
+ def @app.unix?() true end
+ def @app.dynamic_width_stty() 1235 end
+ def @app.dynamic_width_tput() 0 end
- assert_equal 1235, app.terminal_width
+ assert_equal 1235, @app.terminal_width
end
def test_terminal_width_using_tput
- app = Rake::Application.new
- flexmock(app,
- :unix? => true,
- :dynamic_width_stty => 0,
- :dynamic_width_tput => 1236)
+ def @app.unix?() true end
+ def @app.dynamic_width_stty() 0 end
+ def @app.dynamic_width_tput() 1236 end
- assert_equal 1236, app.terminal_width
+ assert_equal 1236, @app.terminal_width
end
def test_terminal_width_using_hardcoded_80
- app = Rake::Application.new
- flexmock(app, :unix? => false)
+ def @app.unix?() true end
- assert_equal 80, app.terminal_width
+ assert_equal 80, @app.terminal_width
end
def test_terminal_width_with_failure
- app = Rake::Application.new
- flexmock(app).should_receive(:unix?).and_throw(RuntimeError)
+ def @app.unix?() raise end
- assert_equal 80, app.terminal_width
+ assert_equal 80, @app.terminal_width
end
def test_no_rakeopt
View
4 test/test_rake_test_task.rb
@@ -93,7 +93,7 @@ def test_run_code_testrb_ruby_1_8_2
t.loader = :testrb
end
- flexmock(test_task).should_receive(:ruby_version).and_return('1.8.2')
+ def test_task.ruby_version() '1.8.2' end
assert_match(/^-S testrb +".*"$/, test_task.run_code)
end
@@ -103,7 +103,7 @@ def test_run_code_testrb_ruby_1_8_6
t.loader = :testrb
end
- flexmock(test_task).should_receive(:ruby_version).and_return('1.8.6')
+ def test_task.ruby_version() '1.8.6' end
assert_match(/^-S testrb +$/, test_task.run_code)
end
View
69 test/test_rake_top_level_functions.rb
@@ -5,28 +5,43 @@ class TestRakeTopLevelFunctions < Rake::TestCase
def setup
super
- @app = Rake.application
- Rake.application = flexmock("app")
- Rake.application.should_receive(:deprecate).
- and_return { |old, new, call| @app.deprecate(old, new, call) }
- end
+ @app = Object.new
- def teardown
- Rake.application = @app
+ def @app.called
+ @called
+ end
- super
+ def @app.method_missing(*a, &b)
+ @called ||= []
+ @called << [a, b]
+ nil
+ end
+
+ Rake.application = @app
end
def test_namespace
- Rake.application.should_receive(:in_namespace).with("xyz", any).once
- namespace "xyz" do end
+ block = proc do end
+
+ namespace("xyz", &block)
+
+ expected = [
+ [[:in_namespace, 'xyz'], block]
+ ]
+
+ assert_equal expected, @app.called
end
def test_import
- Rake.application.should_receive(:add_import).with("x").once.ordered
- Rake.application.should_receive(:add_import).with("y").once.ordered
- Rake.application.should_receive(:add_import).with("z").once.ordered
import('x', 'y', 'z')
+
+ expected = [
+ [[:add_import, 'x'], nil],
+ [[:add_import, 'y'], nil],
+ [[:add_import, 'z'], nil],
+ ]
+
+ assert_equal expected, @app.called
end
def test_when_writing
@@ -51,23 +66,43 @@ def test_when_not_writing
end
def test_missing_constants_task
- Rake.application.should_receive(:const_warning).with(:Task).once
Object.const_missing(:Task)
+
+ expected = [
+ [[:const_warning, :Task], nil]
+ ]
+
+ assert_equal expected, @app.called
end
def test_missing_constants_file_task
- Rake.application.should_receive(:const_warning).with(:FileTask).once
Object.const_missing(:FileTask)
+
+ expected = [
+ [[:const_warning, :FileTask], nil]
+ ]
+
+ assert_equal expected, @app.called
end
def test_missing_constants_file_creation_task
- Rake.application.should_receive(:const_warning).with(:FileCreationTask).once
Object.const_missing(:FileCreationTask)
+
+ expected = [
+ [[:const_warning, :FileCreationTask], nil]
+ ]
+
+ assert_equal expected, @app.called
end
def test_missing_constants_rake_app
- Rake.application.should_receive(:const_warning).with(:RakeApp).once
Object.const_missing(:RakeApp)
+
+ expected = [
+ [[:const_warning, :RakeApp], nil]
+ ]
+
+ assert_equal expected, @app.called
end
def test_missing_other_constant
Please sign in to comment.
Something went wrong with that request. Please try again.