|
1 |
| -require File.expand_path("../spec_helper_without_rails", __FILE__) |
2 |
| - |
3 |
| -module ActiveAdminIntegrationSpecHelper |
4 |
| - extend self |
5 |
| - |
6 |
| - def load_defaults! |
7 |
| - ActiveAdmin.unload! |
8 |
| - ActiveAdmin.load! |
9 |
| - ActiveAdmin.register(Category) |
10 |
| - ActiveAdmin.register(User) |
11 |
| - ActiveAdmin.register(Post){ belongs_to :user, :optional => true } |
12 |
| - reload_menus! |
13 |
| - end |
14 |
| - |
15 |
| - def reload_menus! |
16 |
| - ActiveAdmin.application.namespaces.values.each{|n| n.reset_menu! } |
17 |
| - end |
| 1 | +# This file is copied to spec/ when you run 'rails generate rspec:install' |
| 2 | +ENV["RAILS_ENV"] ||= 'test' |
| 3 | +require File.expand_path("../../test_app/config/environment", __FILE__) |
| 4 | +require 'rspec/rails' |
| 5 | +require 'rspec/autorun' |
18 | 6 |
|
19 |
| - # Sometimes we need to reload the routes within |
20 |
| - # the application to test them out |
21 |
| - def reload_routes! |
22 |
| - Rails.application.reload_routes! |
23 |
| - end |
| 7 | +# Requires supporting ruby files with custom matchers and macros, etc, |
| 8 | +# in spec/support/ and its subdirectories. |
| 9 | +Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} |
24 | 10 |
|
25 |
| - # Helper method to load resources and ensure that Active Admin is |
26 |
| - # setup with the new configurations. |
| 11 | +RSpec.configure do |config| |
| 12 | + # ## Mock Framework |
27 | 13 | #
|
28 |
| - # Eg: |
29 |
| - # load_resources do |
30 |
| - # ActiveAdmin.regiser(Post) |
31 |
| - # end |
| 14 | + # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: |
32 | 15 | #
|
33 |
| - def load_resources |
34 |
| - ActiveAdmin.unload! |
35 |
| - yield |
36 |
| - reload_menus! |
37 |
| - reload_routes! |
38 |
| - end |
39 |
| - |
40 |
| - # Sets up a describe block where you can render controller |
41 |
| - # actions. Uses the Admin::PostsController as the subject |
42 |
| - # for the describe block |
43 |
| - def describe_with_render(*args, &block) |
44 |
| - describe *args do |
45 |
| - include RSpec::Rails::ControllerExampleGroup |
46 |
| - render_views |
47 |
| - # metadata[:behaviour][:describes] = ActiveAdmin.namespaces[:admin].resources['Post'].controller |
48 |
| - module_eval &block |
49 |
| - end |
50 |
| - end |
51 |
| - |
52 |
| - def arbre(assigns = {}, helpers = mock_action_view, &block) |
53 |
| - Arbre::Context.new(assigns, helpers, &block) |
54 |
| - end |
55 |
| - |
56 |
| - def render_arbre_component(assigns = {}, helpers = mock_action_view, &block) |
57 |
| - arbre(assigns, helpers, &block).children.first |
58 |
| - end |
| 16 | + # config.mock_with :mocha |
| 17 | + # config.mock_with :flexmock |
| 18 | + # config.mock_with :rr |
59 | 19 |
|
60 |
| - # Setup a describe block which uses capybara and rails integration |
61 |
| - # test methods. |
62 |
| - def describe_with_capybara(*args, &block) |
63 |
| - describe *args do |
64 |
| - include RSpec::Rails::IntegrationExampleGroup |
65 |
| - module_eval &block |
66 |
| - end |
67 |
| - end |
68 |
| - |
69 |
| - # Returns a fake action view instance to use with our renderers |
70 |
| - def mock_action_view(assigns = {}) |
71 |
| - controller = ActionView::TestCase::TestController.new |
72 |
| - ActionView::Base.send :include, ActionView::Helpers |
73 |
| - ActionView::Base.send :include, ActiveAdmin::ViewHelpers |
74 |
| - ActionView::Base.send :include, Rails.application.routes.url_helpers |
75 |
| - ActionView::Base.new(ActionController::Base.view_paths, assigns, controller) |
76 |
| - end |
77 |
| - alias_method :action_view, :mock_action_view |
78 |
| - |
79 |
| - # A mock resource to register |
80 |
| - class MockResource |
81 |
| - end |
82 |
| - |
83 |
| -end |
84 |
| - |
85 |
| -ENV['RAILS_ENV'] = 'test' |
86 |
| -ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}", __FILE__) |
87 |
| - |
88 |
| -# Create the test app if it doesn't exists |
89 |
| -unless File.exists?(ENV['RAILS_ROOT']) |
90 |
| - system 'rake setup' |
91 |
| -end |
| 20 | + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures |
| 21 | + config.fixture_path = "#{::Rails.root}/spec/fixtures" |
92 | 22 |
|
93 |
| -# Ensure the Active Admin load path is happy |
94 |
| -require 'rails' |
95 |
| -require 'active_admin' |
96 |
| -ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + "/app/admin"] |
97 |
| - |
98 |
| -require ENV['RAILS_ROOT'] + '/config/environment' |
99 |
| - |
100 |
| -require 'rspec/rails' |
101 |
| - |
102 |
| -# Setup Some Admin stuff for us to play with |
103 |
| -include ActiveAdminIntegrationSpecHelper |
104 |
| -load_defaults! |
105 |
| -reload_routes! |
106 |
| - |
107 |
| -# Disabling authentication in specs so that we don't have to worry about |
108 |
| -# it allover the place |
109 |
| -ActiveAdmin.application.authentication_method = false |
110 |
| -ActiveAdmin.application.current_user_method = false |
111 |
| - |
112 |
| -# Don't add asset cache timestamps. Makes it easy to integration |
113 |
| -# test for the presence of an asset file |
114 |
| -ENV["RAILS_ASSET_ID"] = '' |
115 |
| - |
116 |
| -RSpec.configure do |config| |
| 23 | + # If you're not using ActiveRecord, or you'd prefer not to run each of your |
| 24 | + # examples within a transaction, remove the following line or assign false |
| 25 | + # instead of true. |
117 | 26 | config.use_transactional_fixtures = true
|
118 |
| - config.use_instantiated_fixtures = false |
119 |
| -end |
120 |
| - |
121 |
| -# All RSpec configuration needs to happen before any examples |
122 |
| -# or else it whines. |
123 |
| -require 'integration_example_group' |
124 |
| -RSpec.configure do |c| |
125 |
| - c.include RSpec::Rails::IntegrationExampleGroup, :example_group => { :file_path => /\bspec\/integration\// } |
126 |
| -end |
127 | 27 |
|
128 |
| -# Ensure this is defined for Ruby 1.8 |
129 |
| -module MiniTest; class Assertion < Exception; end; end |
| 28 | + # If true, the base class of anonymous controllers will be inferred |
| 29 | + # automatically. This will be the default behavior in future versions of |
| 30 | + # rspec-rails. |
| 31 | + config.infer_base_class_for_anonymous_controllers = false |
130 | 32 |
|
131 |
| -RSpec::Matchers.define :have_tag do |*args| |
132 |
| - |
133 |
| - match_unless_raises Test::Unit::AssertionFailedError do |response| |
134 |
| - tag = args.shift |
135 |
| - content = args.first.is_a?(Hash) ? nil : args.shift |
136 |
| - |
137 |
| - options = { |
138 |
| - :tag => tag.to_s |
139 |
| - }.merge(args[0] || {}) |
140 |
| - |
141 |
| - options[:content] = content if content |
142 |
| - |
143 |
| - begin |
144 |
| - begin |
145 |
| - assert_tag(options) |
146 |
| - rescue NoMethodError |
147 |
| - # We are not in a controller, so let's do the checking ourselves |
148 |
| - doc = HTML::Document.new(response, false, false) |
149 |
| - tag = doc.find(options) |
150 |
| - assert tag, "expected tag, but no tag found matching #{options.inspect} in:\n#{response.inspect}" |
151 |
| - end |
152 |
| - # In Ruby 1.9, MiniTest::Assertion get's raised, so we'll |
153 |
| - # handle raising a Test::Unit::AssertionFailedError |
154 |
| - rescue MiniTest::Assertion => e |
155 |
| - raise Test::Unit::AssertionFailedError, e.message |
156 |
| - end |
157 |
| - end |
| 33 | + # Run specs in random order to surface order dependencies. If you find an |
| 34 | + # order dependency and want to debug it, you can fix the order by providing |
| 35 | + # the seed, which is printed after each run. |
| 36 | + # --seed 1234 |
| 37 | + config.order = "random" |
158 | 38 | end
|
159 |
| - |
160 |
| -# improve the performance of the specs suite by not logging anything |
161 |
| -# see http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/ |
162 |
| -Rails.logger.level = 4 |
0 commit comments