Permalink
Browse files

Switch spec_helper to rails_helper, in accord with upgrade guidelines

  • Loading branch information...
1 parent 181381d commit faf7f09a675d828b0ac4fb0fa78a65c95381b81d @petergoldstein petergoldstein committed Jun 3, 2014
Showing with 284 additions and 283 deletions.
  1. +1 −0 Guardfile
  2. +1 −1 features/support/env.rb
  3. +186 −0 spec/rails_helper.rb
  4. +1 −1 spec/requests/default_namespace_spec.rb
  5. +1 −1 spec/requests/javascript_spec.rb
  6. +1 −1 spec/requests/memory_spec.rb
  7. +1 −1 spec/requests/stylesheets_spec.rb
  8. +12 −181 spec/spec_helper.rb
  9. +0 −17 spec/spec_helper_without_rails.rb
  10. +1 −1 spec/unit/abstract_view_factory_spec.rb
  11. +1 −1 spec/unit/action_builder_spec.rb
  12. +1 −1 spec/unit/active_admin_spec.rb
  13. +1 −1 spec/unit/application_spec.rb
  14. +1 −1 spec/unit/asset_registration_spec.rb
  15. +1 −1 spec/unit/authorization/authorization_adapter_spec.rb
  16. +1 −1 spec/unit/authorization/controller_authorization_spec.rb
  17. +1 −1 spec/unit/auto_link_spec.rb
  18. +1 −1 spec/unit/batch_actions/resource_spec.rb
  19. +1 −1 spec/unit/batch_actions/settings_spec.rb
  20. +1 −1 spec/unit/belongs_to_spec.rb
  21. +1 −1 spec/unit/cancan_adapter_spec.rb
  22. +1 −1 spec/unit/comments_spec.rb
  23. +1 −1 spec/unit/component_spec.rb
  24. +1 −1 spec/unit/controller_filters_spec.rb
  25. +1 −1 spec/unit/csv_builder_spec.rb
  26. +1 −1 spec/unit/devise_spec.rb
  27. +1 −1 spec/unit/dsl_spec.rb
  28. +1 −1 spec/unit/event_spec.rb
  29. +1 −1 spec/unit/filters/filter_form_builder_spec.rb
  30. +1 −1 spec/unit/filters/resource_spec.rb
  31. +1 −1 spec/unit/form_builder_spec.rb
  32. +1 −1 spec/unit/generators/install_spec.rb
  33. +1 −1 spec/unit/helpers/collection_spec.rb
  34. +1 −1 spec/unit/helpers/scope_chain_spec.rb
  35. +1 −1 spec/unit/helpers/settings_spec.rb
  36. +1 −1 spec/unit/menu_collection_spec.rb
  37. +1 −1 spec/unit/menu_item_spec.rb
  38. +1 −1 spec/unit/menu_spec.rb
  39. +1 −1 spec/unit/namespace/authorization_spec.rb
  40. +1 −1 spec/unit/namespace/register_page_spec.rb
  41. +1 −1 spec/unit/namespace/register_resource_spec.rb
  42. +1 −1 spec/unit/namespace_spec.rb
  43. +1 −1 spec/unit/order_clause_spec.rb
  44. +1 −1 spec/unit/page_controller_spec.rb
  45. +1 −1 spec/unit/page_spec.rb
  46. +1 −1 spec/unit/pretty_format_spec.rb
  47. +1 −1 spec/unit/pundit_adapter_spec.rb
  48. +1 −1 spec/unit/resource/action_items_spec.rb
  49. +1 −1 spec/unit/resource/menu_spec.rb
  50. +1 −1 spec/unit/resource/naming_spec.rb
  51. +1 −1 spec/unit/resource/page_presenters_spec.rb
  52. +1 −1 spec/unit/resource/pagination_spec.rb
  53. +1 −1 spec/unit/resource/routes_spec.rb
  54. +1 −1 spec/unit/resource/scopes_spec.rb
  55. +1 −1 spec/unit/resource/sidebars_spec.rb
  56. +1 −1 spec/unit/resource_collection_spec.rb
  57. +1 −1 spec/unit/resource_controller/data_access_spec.rb
  58. +1 −1 spec/unit/resource_controller/decorators_spec.rb
  59. +1 −1 spec/unit/resource_controller/sidebars_spec.rb
  60. +1 −1 spec/unit/resource_controller_spec.rb
  61. +1 −1 spec/unit/resource_registration_spec.rb
  62. +1 −1 spec/unit/resource_spec.rb
  63. +1 −1 spec/unit/routing_spec.rb
  64. +1 −1 spec/unit/scope_spec.rb
  65. +1 −1 spec/unit/settings_spec.rb
  66. +1 −1 spec/unit/view_factory_spec.rb
  67. +1 −1 spec/unit/view_helpers/breadcrumbs_spec.rb
  68. +1 −1 spec/unit/view_helpers/display_name_spec.rb
  69. +1 −1 spec/unit/view_helpers/download_format_links_helper_spec.rb
  70. +1 −1 spec/unit/view_helpers/form_helper_spec.rb
  71. +1 −1 spec/unit/view_helpers/method_or_proc_helper_spec.rb
  72. +1 −1 spec/unit/views/components/action_list_popover_spec.rb
  73. +1 −1 spec/unit/views/components/attributes_table_spec.rb
  74. +1 −1 spec/unit/views/components/batch_action_popover_spec.rb
  75. +1 −1 spec/unit/views/components/blank_slate_spec.rb
  76. +1 −1 spec/unit/views/components/columns_spec.rb
  77. +1 −1 spec/unit/views/components/index_list_spec.rb
  78. +1 −1 spec/unit/views/components/paginated_collection_spec.rb
  79. +1 −1 spec/unit/views/components/panel_spec.rb
  80. +1 −1 spec/unit/views/components/popover_spec.rb
  81. +1 −1 spec/unit/views/components/sidebar_section_spec.rb
  82. +1 −1 spec/unit/views/components/site_title_spec.rb
  83. +1 −1 spec/unit/views/components/status_tag_spec.rb
  84. +1 −1 spec/unit/views/components/table_for_spec.rb
  85. +1 −1 spec/unit/views/pages/form_spec.rb
  86. +1 −1 spec/unit/views/pages/index_spec.rb
  87. +1 −1 spec/unit/views/pages/layout_spec.rb
  88. +1 −1 spec/unit/views/pages/show_spec.rb
  89. +1 −1 spec/unit/views/tabbed_navigation_spec.rb
View
@@ -4,4 +4,5 @@ guard 'rspec', :all_on_start => false, :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/active_admin/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec/" }
+ watch('spec/rails_helper.rb') { "spec/" }
end
@@ -6,7 +6,7 @@
ENV["RAILS_ENV"] ||= "cucumber"
-require File.expand_path('../../../spec/spec_helper_without_rails', __FILE__)
+require File.expand_path('../../../spec/spec_helper', __FILE__)
ENV['RAILS_ROOT'] = File.expand_path("../../../spec/rails/rails-#{ENV["RAILS"]}", __FILE__)
View
@@ -0,0 +1,186 @@
+require 'spec_helper'
+
+module ActiveAdminIntegrationSpecHelper
+ extend self
+
+ def load_defaults!
+ ActiveAdmin.unload!
+ ActiveAdmin.load!
+ ActiveAdmin.register(Category)
+ ActiveAdmin.register(User)
+ ActiveAdmin.register(Post){ belongs_to :user, optional: true }
+ reload_menus!
+ end
+
+ def reload_menus!
+ ActiveAdmin.application.namespaces.values.each{|n| n.reset_menu! }
+ end
+
+ # Sometimes we need to reload the routes within
+ # the application to test them out
+ def reload_routes!
+ Rails.application.reload_routes!
+ end
+
+ # Helper method to load resources and ensure that Active Admin is
+ # setup with the new configurations.
+ #
+ # Eg:
+ # load_resources do
+ # ActiveAdmin.regiser(Post)
+ # end
+ #
+ def load_resources
+ ActiveAdmin.unload!
+ yield
+ reload_menus!
+ reload_routes!
+ end
+
+ # Sets up a describe block where you can render controller
+ # actions. Uses the Admin::PostsController as the subject
+ # for the describe block
+ def describe_with_render(*args, &block)
+ describe *args do
+ include RSpec::Rails::ControllerExampleGroup
+ render_views
+ # metadata[:behaviour][:describes] = ActiveAdmin.namespaces[:admin].resources['Post'].controller
+ module_eval &block
+ end
+ end
+
+ def arbre(assigns = {}, helpers = mock_action_view, &block)
+ Arbre::Context.new(assigns, helpers, &block)
+ end
+
+ def render_arbre_component(assigns = {}, helpers = mock_action_view, &block)
+ arbre(assigns, helpers, &block).children.first
+ end
+
+ # Setup a describe block which uses capybara and rails integration
+ # test methods.
+ def describe_with_capybara(*args, &block)
+ describe *args do
+ include RSpec::Rails::IntegrationExampleGroup
+ module_eval &block
+ end
+ end
+
+ # Returns a fake action view instance to use with our renderers
+ def mock_action_view(assigns = {})
+ controller = ActionView::TestCase::TestController.new
+ ActionView::Base.send :include, ActionView::Helpers
+ ActionView::Base.send :include, ActiveAdmin::ViewHelpers
+ ActionView::Base.send :include, Rails.application.routes.url_helpers
+ ActionView::Base.new(ActionController::Base.view_paths, assigns, controller)
+ end
+ alias_method :action_view, :mock_action_view
+
+ # A mock resource to register
+ class MockResource
+ end
+
+ def with_translation(translation)
+ I18n.backend.store_translations :en, translation
+ yield
+ ensure
+ I18n.backend.reload!
+ end
+
+end
+
+ENV['RAILS_ENV'] = 'test'
+ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}", __FILE__)
+
+# Create the test app if it doesn't exists
+unless File.exists?(ENV['RAILS_ROOT'])
+ system 'rake setup'
+end
+
+require 'rails'
+require 'active_record'
+require 'active_admin'
+require 'devise'
+ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + "/app/admin"]
+
+require ENV['RAILS_ROOT'] + '/config/environment'
+
+require 'rspec/rails'
+
+# Setup Some Admin stuff for us to play with
+include ActiveAdminIntegrationSpecHelper
+load_defaults!
+reload_routes!
+
+# Disabling authentication in specs so that we don't have to worry about
+# it allover the place
+ActiveAdmin.application.authentication_method = false
+ActiveAdmin.application.current_user_method = false
+
+# Don't add asset cache timestamps. Makes it easy to integration
+# test for the presence of an asset file
+ENV["RAILS_ASSET_ID"] = ''
+
+RSpec.configure do |config|
+ config.use_transactional_fixtures = true
+ config.use_instantiated_fixtures = false
+ config.include Devise::TestHelpers, type: :controller
+ config.render_views = false
+ config.filter_run focus: true
+ config.filter_run_excluding skip: true
+ config.run_all_when_everything_filtered = true
+end
+
+# All RSpec configuration needs to happen before any examples
+# or else it whines.
+require 'integration_example_group'
+RSpec.configure do |c|
+ c.include RSpec::Rails::IntegrationExampleGroup, example_group: { file_path: /\bspec\/requests\// }
+ c.include Devise::TestHelpers, type: :controller
+end
+
+# Ensure this is defined for Ruby 1.8
+module MiniTest; class Assertion < Exception; end; end
+
+RSpec::Matchers.define :have_tag do |*args|
+
+ match_unless_raises Test::Unit::AssertionFailedError do |response|
+ tag = args.shift
+ content = args.first.is_a?(Hash) ? nil : args.shift
+
+ options = {
+ tag: tag.to_s
+ }.merge(args[0] || {})
+
+ options[:content] = content if content
+
+ begin
+ begin
+ assert_tag(options)
+ rescue NoMethodError
+ # We are not in a controller, so let's do the checking ourselves
+ doc = HTML::Document.new(response, false, false)
+ tag = doc.find(options)
+ assert tag, "expected tag, but no tag found matching #{options.inspect} in:\n#{response.inspect}"
+ end
+ # In Ruby 1.9, MiniTest::Assertion get's raised, so we'll
+ # handle raising a Test::Unit::AssertionFailedError
+ rescue MiniTest::Assertion => e
+ raise Test::Unit::AssertionFailedError, e.message
+ end
+ end
+end
+
+# improve the performance of the specs suite by not logging anything
+# see http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/
+Rails.logger.level = 4
+
+
+# Improves performance by forcing the garbage collector to run less often.
+unless ENV['DEFER_GC'] == '0' || ENV['DEFER_GC'] == 'false'
+ require 'support/deferred_garbage_collection'
+ RSpec.configure do |config|
+ config.before(:all) { DeferredGarbageCollection.start }
+ config.after(:all) { DeferredGarbageCollection.reconsider }
+ end
+end
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require 'rails_helper'
describe ActiveAdmin::Application, :type => :request do
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require 'rails_helper'
require 'jslint'
%x[which java]
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require 'rails_helper'
describe "Memory Leak", :type => :request do
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require 'rails_helper'
describe "Stylesheets", :type => :request do
Oops, something went wrong.

0 comments on commit faf7f09

Please sign in to comment.