Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove mocha

  • Loading branch information...
commit 3a9a81fa85bb13011afa1e3e08d126b17d9ce94f 1 parent 774dc49
@nashby nashby authored
View
1  Gemfile
@@ -8,5 +8,4 @@ gem 'activemodel', '>= 4.0.0.beta1', '< 4.1'
gem 'actionpack', '>= 4.0.0.beta1', '< 4.1'
gem 'rake'
gem 'rdoc'
-gem 'mocha', require: false
gem 'tzinfo'
View
4 Gemfile.lock
@@ -29,10 +29,7 @@ GEM
erubis (2.7.0)
i18n (0.6.2)
json (1.7.7)
- metaclass (0.0.1)
minitest (4.6.1)
- mocha (0.13.2)
- metaclass (~> 0.0.1)
multi_json (1.6.1)
rack (1.5.2)
rack-test (0.6.2)
@@ -58,7 +55,6 @@ DEPENDENCIES
actionpack (>= 4.0.0.beta1, < 4.1)
activemodel (>= 4.0.0.beta1, < 4.1)
country_select (~> 1.1.1)
- mocha
railties (>= 4.0.0.beta1, < 4.1)
rake
rdoc
View
22 test/form_builder/association_test.rb
@@ -41,36 +41,46 @@ def with_association_for(object, *args)
end
test 'builder preloads collection association' do
- value = @user.tags = Object.new
- value.expects(:to_a).returns(value)
+ value = @user.tags = MiniTest::Mock.new
+ value.expect(:to_a, value)
with_association_for @user, :tags
assert_select 'form select.select#user_tag_ids'
assert_select 'form select option[value=1]', 'Tag 1'
assert_select 'form select option[value=2]', 'Tag 2'
assert_select 'form select option[value=3]', 'Tag 3'
+
+ value.verify
end
test 'builder does not preload collection association if preload is false' do
- value = @user.tags = Object.new
- value.expects(:to_a).never
+ value = @user.tags = MiniTest::Mock.new
+ value.expect(:to_a, nil)
with_association_for @user, :tags, preload: false
assert_select 'form select.select#user_tag_ids'
assert_select 'form select option[value=1]', 'Tag 1'
assert_select 'form select option[value=2]', 'Tag 2'
assert_select 'form select option[value=3]', 'Tag 3'
+
+ assert_raises MockExpectationError do
+ value.verify
+ end
end
test 'builder does not preload non-collection association' do
- value = @user.company = Object.new
- value.expects(:to_a).never
+ value = @user.company = MiniTest::Mock.new
+ value.expect(:to_a, nil)
with_association_for @user, :company
assert_select 'form select.select#user_company_id'
assert_select 'form select option[value=1]', 'Company 1'
assert_select 'form select option[value=2]', 'Company 2'
assert_select 'form select option[value=3]', 'Company 3'
+
+ assert_raises MockExpectationError do
+ value.verify
+ end
end
# ASSOCIATIONS - BELONGS TO
View
18 test/form_builder/general_test.rb
@@ -156,18 +156,16 @@ def with_custom_form_for(object, *args, &block)
end
test 'builder should generate file for file columns' do
- @user.avatar = mock("file")
- @user.avatar.expects(:respond_to?).with(:mounted_as).returns(false)
- @user.avatar.expects(:respond_to?).with(:file?).returns(false)
- @user.avatar.expects(:respond_to?).with(:public_filename).returns(true)
+ @user.avatar = MiniTest::Mock.new
+ @user.avatar.expect(:public_filename, true)
with_form_for @user, :avatar
assert_select 'form input#user_avatar.file'
end
test 'builder should generate file for attributes that are real db columns but have file methods' do
- @user.home_picture = mock("file")
- @user.home_picture.expects(:respond_to?).with(:mounted_as).returns(true)
+ @user.home_picture = MiniTest::Mock.new
+ @user.home_picture.expect(:mounted_as, true)
with_form_for @user, :home_picture
assert_select 'form input#user_home_picture.file'
@@ -264,10 +262,10 @@ def with_custom_form_for(object, *args, &block)
test 'builder should be able to disable a hint even if it exists in i18n' do
store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do
- SimpleForm::Inputs::Base.any_instance.expects(:hint).never
-
- with_form_for @user, :name, hint: false
- assert_no_select 'span.hint'
+ stub_any_instance(SimpleForm::Inputs::Base, :hint, -> { raise 'Never' }) do
+ with_form_for @user, :name, hint: false
+ assert_no_select 'span.hint'
+ end
end
end
View
22 test/support/misc_helpers.rb
@@ -24,6 +24,28 @@ def swap(object, new_values)
end
end
+ def stub_any_instance(klass, method, value)
+ klass.class_eval do
+ alias_method :"new_#{method}", method
+
+ define_method(method) do
+ if value.respond_to?(:call)
+ value.call
+ else
+ value
+ end
+ end
+ end
+
+ yield
+ ensure
+ klass.class_eval do
+ undef_method method
+ alias_method method, :"new_#{method}"
+ undef_method :"new_#{method}"
+ end
+ end
+
def swap_wrapper(name=:default, wrapper=self.custom_wrapper)
old = SimpleForm.wrappers[name]
SimpleForm.wrappers[name] = wrapper
View
3  test/test_helper.rb
@@ -1,8 +1,7 @@
require 'rubygems'
require 'bundler/setup'
-require 'test/unit'
-require 'mocha/setup'
+require 'minitest/autorun'
require 'active_model'
require 'action_controller'

0 comments on commit 3a9a81f

Please sign in to comment.
Something went wrong with that request. Please try again.