remove mocha

This commit is contained in:
Vasiliy Ermolovich 2013-02-28 00:12:37 +03:00
parent 774dc49820
commit 3a9a81fa85
6 changed files with 47 additions and 23 deletions

View File

@ -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 File

@ -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 File

@ -41,36 +41,46 @@ class AssociationTest < ActionView::TestCase
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 File

@ -156,18 +156,16 @@ class FormBuilderTest < ActionView::TestCase
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 @@ class FormBuilderTest < ActionView::TestCase
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 File

@ -24,6 +24,28 @@ module MiscHelpers
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 File

@ -1,8 +1,7 @@
require 'rubygems'
require 'bundler/setup'
require 'test/unit'
require 'mocha/setup'
require 'minitest/autorun'
require 'active_model'
require 'action_controller'