spec/spec_helper.rb in magic_grid-0.10.4 vs spec/spec_helper.rb in magic_grid-0.11.0
- old
+ new
@@ -7,17 +7,20 @@
add_filter '/spec/'
add_filter '/test/'
end
end
+require 'magic_grid/logger'
require 'action_view'
require 'rails'
+require 'test/unit'
+require 'action_controller'
begin
require 'will_paginate'
require 'will_paginate/array'
- require 'will_paginate/view_helpers'
+ require 'will_paginate/view_helpers/action_view'
puts "Testing with WillPaginate"
rescue LoadError
puts "skipping WillPaginate"
end
@@ -29,41 +32,50 @@
puts "skipping Kaminari"
end
Rails.backtrace_cleaner.remove_silencers!
-# I has a sad :-(
-module Rails
- def logger.debug(*ignore) end
+class NullObject
+ def method_missing(*args, &block) self; end
+ def nil?; true; end
end
module ActionFaker
- def output_buffer=(o)
- @output_buffer = o
+ attr_accessor :output_buffer
+ def url_for(*args)
+ "fake_url(#{args.inspect})"
end
- def output_buffer()
- @output_buffer
+end
+
+class TextSelector
+ include ActionDispatch::Assertions::SelectorAssertions
+ include Test::Unit::Assertions
+ def initialize(text)
+ @selected = HTML::Document.new(text).root.children
end
- def url_for
- "fake_url"
+end
+
+RSpec::Matchers.define :match_select do |*expected|
+ match do |actual|
+ TextSelector.new(actual).assert_select(*expected)
end
- def controller
- stub_controller = ActionController::Base.new
- def stub_controller.params(*ignored) {} end
- stub_controller
- end
end
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.include ActionView::Helpers
- config.include WillPaginate::ViewHelpers if Module.const_defined? :WillPaginate
+ config.include WillPaginate::ActionView if Module.const_defined? :WillPaginate
config.include Kaminari::ActionViewExtension if Module.const_defined? :Kaminari
config.include ActionFaker
+
+ config.before do
+ MagicGrid.logger = NullObject.new
+ end
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234