Skip to content
Browse files

Don't require the things that are already required by Rails.

Closes #101.
  • Loading branch information...
1 parent 614fd02 commit 471d6d87c1f3aff7b9e11ff195b382c7d253042b @dchelimsky dchelimsky committed
View
2 lib/rspec/rails.rb
@@ -1,3 +1,5 @@
+require 'webrat'
+
require 'rspec/core'
require 'rspec/rails/monkey'
require 'rspec/rails/extensions'
View
3 lib/rspec/rails/example/controller_example_group.rb
@@ -1,6 +1,3 @@
-require 'action_controller'
-require 'webrat'
-
module RSpec::Rails
# Extends ActionController::TestCase::Behavior to work with RSpec.
#
View
2 lib/rspec/rails/example/helper_example_group.rb
@@ -1,6 +1,4 @@
-require 'action_view'
require 'rspec/rails/view_assigns'
-require 'webrat'
module RSpec::Rails
# Extends ActionView::TestCase::Behavior
View
3 lib/rspec/rails/example/mailer_example_group.rb
@@ -1,6 +1,3 @@
-require 'action_mailer'
-require 'webrat'
-
module RSpec::Rails
module MailerExampleGroup
extend ActiveSupport::Concern
View
3 lib/rspec/rails/example/request_example_group.rb
@@ -1,6 +1,3 @@
-require 'action_dispatch'
-require 'webrat'
-
module RSpec::Rails
# Extends ActionDispatch::Integration::Runner to work with RSpec.
#
View
2 lib/rspec/rails/example/view_example_group.rb
@@ -1,6 +1,4 @@
-require 'action_view'
require 'rspec/rails/view_assigns'
-require 'webrat'
module RSpec::Rails
# Extends ActionView::TestCase::Behavior
View
10 lib/rspec/rails/matchers.rb
@@ -8,16 +8,6 @@ module Matchers
end
begin
- require "active_record"
-rescue LoadError
-end
-
-begin
- require "action_controller"
-rescue LoadError
-end
-
-begin
require 'test/unit/assertionfailederror'
rescue LoadError
module Test
View
96 lib/rspec/rails/monkey/action_mailer/test_case.rb
@@ -1,69 +1,69 @@
-require 'action_mailer'
+if defined?(ActionMailer)
+ module ActionMailer
+ unless defined?(ActionMailer::TestCase::Behavior)
+ class TestCase < ActiveSupport::TestCase
+ module Behavior
+ extend ActiveSupport::Concern
-module ActionMailer
- unless defined?(ActionMailer::TestCase::Behavior)
- class TestCase < ActiveSupport::TestCase
- module Behavior
- extend ActiveSupport::Concern
+ include TestHelper
- include TestHelper
+ module ClassMethods
+ def tests(mailer)
+ write_inheritable_attribute(:mailer_class, mailer)
+ end
- module ClassMethods
- def tests(mailer)
- write_inheritable_attribute(:mailer_class, mailer)
- end
+ def mailer_class
+ if mailer = read_inheritable_attribute(:mailer_class)
+ mailer
+ else
+ tests determine_default_mailer(name)
+ end
+ end
- def mailer_class
- if mailer = read_inheritable_attribute(:mailer_class)
- mailer
- else
- tests determine_default_mailer(name)
+ def determine_default_mailer(name)
+ name.sub(/Test$/, '').constantize
+ rescue NameError => e
+ raise NonInferrableMailerError.new(name)
end
end
- def determine_default_mailer(name)
- name.sub(/Test$/, '').constantize
- rescue NameError => e
- raise NonInferrableMailerError.new(name)
- end
- end
+ module InstanceMethods
- module InstanceMethods
+ protected
- protected
+ def initialize_test_deliveries
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries.clear
+ end
- def initialize_test_deliveries
- ActionMailer::Base.delivery_method = :test
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.deliveries.clear
- end
+ def set_expected_mail
+ @expected = Mail.new
+ @expected.content_type ["text", "plain", { "charset" => charset }]
+ @expected.mime_version = '1.0'
+ end
- def set_expected_mail
- @expected = Mail.new
- @expected.content_type ["text", "plain", { "charset" => charset }]
- @expected.mime_version = '1.0'
- end
+ private
- private
+ def charset
+ "UTF-8"
+ end
- def charset
- "UTF-8"
- end
+ def encode(subject)
+ Mail::Encodings.q_value_encode(subject, charset)
+ end
- def encode(subject)
- Mail::Encodings.q_value_encode(subject, charset)
+ def read_fixture(action)
+ IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
+ end
end
- def read_fixture(action)
- IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
+ included do
+ setup :initialize_test_deliveries
+ setup :set_expected_mail
end
end
-
- included do
- setup :initialize_test_deliveries
- setup :set_expected_mail
- end
end
end
end
-end
+end
View
1 lib/rspec/rails/view_rendering.rb
@@ -1,4 +1,3 @@
-require 'action_controller'
require 'action_view/testing/resolvers'
module RSpec
View
3 spec/spec_helper.rb
@@ -1,6 +1,9 @@
require 'bundler'
Bundler.setup
+require 'active_record'
+require 'action_controller'
+require 'action_mailer'
require 'rspec/rails'
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

0 comments on commit 471d6d8

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