Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Set ActiveSupport::TestCase as the base class for ExampleGroups. This
Browse files Browse the repository at this point in the history
ensures that config.include MyModule includes MyModule in all example
group types.
  • Loading branch information
dchelimsky committed Feb 11, 2009
1 parent 4297b36 commit 8721492
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 25 deletions.
7 changes: 7 additions & 0 deletions lib/spec/rails.rb
Expand Up @@ -19,3 +19,10 @@
require 'spec/rails/example'
require 'spec/rails/extensions'
require 'spec/rails/interop/testcase'

Spec::Example::ExampleGroupFactory.default(ActiveSupport::TestCase)

if ActionView::Base.respond_to?(:cache_template_extension)
ActionView::Base.cache_template_extensions = false
end

1 change: 0 additions & 1 deletion lib/spec/rails/example.rb
Expand Up @@ -2,7 +2,6 @@

require 'spec/rails/example/assigns_hash_proxy'
require "spec/rails/example/render_observer"
require "spec/rails/example/rails_example_group"
require "spec/rails/example/model_example_group"
require "spec/rails/example/functional_example_group"
require "spec/rails/example/controller_example_group"
Expand Down
2 changes: 1 addition & 1 deletion lib/spec/rails/example/model_example_group.rb
Expand Up @@ -6,7 +6,7 @@ module Example
# Model examples use Spec::Rails::Example::ModelExampleGroup, which
# provides support for fixtures and some custom expectations via extensions
# to ActiveRecord::Base.
class ModelExampleGroup < RailsExampleGroup
class ModelExampleGroup < ActiveSupport::TestCase
Spec::Example::ExampleGroupFactory.register(:model, self)
end
end
Expand Down
17 changes: 0 additions & 17 deletions lib/spec/rails/example/rails_example_group.rb

This file was deleted.

2 changes: 2 additions & 0 deletions spec/spec/rails/example/controller_example_group_spec.rb
Expand Up @@ -6,6 +6,8 @@
controller_name :controller_spec
integrate_views if mode == 'integration'

accesses_configured_helper_methods

it "should use the controller as the implicit subject" do
subject.should == controller
end
Expand Down
10 changes: 5 additions & 5 deletions spec/spec/rails/example/example_group_factory_spec.rb
Expand Up @@ -24,21 +24,21 @@ module Example
example_group.superclass.should == Spec::Rails::Example::ModelExampleGroup
end

it "should return a RailsExampleGroup when given :spec_path => '/blah/spec/foo/' (anything other than controllers, views and helpers)" do
it "should return an ActiveSupport::TestCase when given :spec_path => '/blah/spec/foo/' (anything other than controllers, views and helpers)" do
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
"name", :spec_path => '/blah/spec/foo/blah.rb'
) {}
example_group.superclass.should == Spec::Rails::Example::RailsExampleGroup
example_group.superclass.should == ActiveSupport::TestCase
end

it "should return a RailsExampleGroup when given :spec_path => '\\blah\\spec\\foo\\' (windows format) (anything other than controllers, views and helpers)" do
it "should return an ActiveSupport::TestCase when given :spec_path => '\\blah\\spec\\foo\\' (windows format) (anything other than controllers, views and helpers)" do
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
"name", :spec_path => '\\blah\\spec\\foo\\blah.rb'
) {}
example_group.superclass.should == Spec::Rails::Example::RailsExampleGroup
example_group.superclass.should == ActiveSupport::TestCase
end

it "should return a ViewExampleGroup when given :type => :model" do
it "should return a ViewExampleGroup when given :type => :view" do
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
"name", :type => :view
) {}
Expand Down
2 changes: 2 additions & 0 deletions spec/spec/rails/example/helper_example_group_spec.rb
Expand Up @@ -16,6 +16,8 @@ module Example
describe HelperExampleGroup, :type => :helper do
helper_name :explicit

accesses_configured_helper_methods

it "DEPRECATED should have direct access to methods defined in helpers" do
method_in_explicit_helper.should =~ /text from a method/
end
Expand Down
4 changes: 3 additions & 1 deletion spec/spec/rails/example/model_example_group_spec.rb
Expand Up @@ -4,7 +4,9 @@ module Spec
module Rails
module Example
describe ModelExampleGroup do
it "should clear its name from the description" do
accesses_configured_helper_methods

it "clears its name from the description" do
group = describe("foo", :type => :model) do
$nested_group = describe("bar") do
end
Expand Down
2 changes: 2 additions & 0 deletions spec/spec/rails/example/view_example_group_spec.rb
Expand Up @@ -4,6 +4,8 @@
before(:each) do
render "view_spec/implicit_helper"
end

accesses_configured_helper_methods

it "should include the helper" do
response.should have_tag('div', :content => "This is text from a method in the ViewSpecHelper")
Expand Down
18 changes: 18 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -58,3 +58,21 @@ def should_pass
map.connect ":controller/:action/:id"
end

module HelperMethods
def method_in_module_included_in_configuration
end
end

module HelperMacros
def accesses_configured_helper_methods
it "has access to methods in modules included in configuration" do
method_in_module_included_in_configuration
end
end
end

Spec::Runner.configure do |config|
config.include HelperMethods
config.extend HelperMacros
end

0 comments on commit 8721492

Please sign in to comment.