Skip to content

Commit

Permalink
Normalize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Feb 3, 2012
1 parent 043828e commit c7a3de0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 112 deletions.
41 changes: 41 additions & 0 deletions test/dummy.rb
@@ -0,0 +1,41 @@
ENV["RAILS_ENV"] = "test"

require "active_support"
require "action_controller"
require "rails/railtie"


class Dummy
Routes = ActionDispatch::Routing::RouteSet.new
Routes.draw do
match ':controller(/:action(/:id))'
end
end

ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
ActionController::Base.send :include, Dummy::Routes.url_helpers

class ActiveSupport::TestCase

setup do
@routes = Dummy::Routes
end


def controller
@controller_proxy ||= ControllerProxy.new(@controller)
end

class ControllerProxy
def initialize(controller)
@controller = controller
end
def method_missing(method, *args)
@controller.instance_eval do
m = method(method)
m.call(*args)
end
end
end

end
42 changes: 9 additions & 33 deletions test/test_helper.rb
@@ -1,44 +1,20 @@
require 'test/unit'
require 'mocha'

ENV["RAILS_ENV"] = "test"

require "active_support"
require "action_controller"
require "rails/railtie"
require 'dummy'

$:.unshift File.expand_path('../../lib', __FILE__)
require 'tabs_on_rails'

ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')

TabsOnRails::Routes = ActionDispatch::Routing::RouteSet.new
TabsOnRails::Routes.draw do
match ':controller(/:action(/:id))'
end

ActionController::Base.send :include, TabsOnRails::Routes.url_helpers

class ActiveSupport::TestCase
setup do
@routes = TabsOnRails::Routes
end


def controller
@controller_proxy ||= ControllerProxy.new(@controller)
end

class ControllerProxy
def initialize(controller)
@controller = controller
end
def method_missing(method, *args)
@controller.instance_eval do
m = method(method)
m.call(*args)
end
def current_tab(namespace)
case namespace
when nil, :default
:dashboard
when :foospace
:footab
else
:elsetab
end
end

end
19 changes: 2 additions & 17 deletions test/unit/tabs/block_builder_test.rb
@@ -1,21 +1,6 @@
require 'test_helper'

class BlockBuilderTest < ActionView::TestCase
tests TabsOnRails::ActionController::HelperMethods

include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper

def current_tab(namespace)
case namespace
when nil, :default
:dashboard
when :foospace
:footab
else
:elsetab
end
end

class BlockBuilder < TabsOnRails::Tabs::TabsBuilder
def tab_for(tab, name, options, item_options = {}, &block)
Expand All @@ -26,9 +11,9 @@ def tab_for(tab, name, options, item_options = {}, &block)
end
end


def setup
@klass = BlockBuilder
@builder = @klass.new(self)
@builder = BlockBuilder.new(self)
end

def test_tab_for_with_block
Expand Down
20 changes: 2 additions & 18 deletions test/unit/tabs/builder_test.rb
@@ -1,25 +1,9 @@
require 'test_helper'

class BuilderTest < ActiveSupport::TestCase

Template = Class.new do
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper

def current_tab(namespace)
case namespace
when nil, :default
:dashboard
when :foospace
:footab
else
:elsetab
end
end
end
class BuilderTest < ActionView::TestCase

def setup
@template = Template.new
@template = self
@builder = TabsOnRails::Tabs::Builder.new(@template)
end

Expand Down
23 changes: 3 additions & 20 deletions test/unit/tabs/tabs_builder_test.rb
@@ -1,30 +1,13 @@
require 'test_helper'

class TabsBuilderTest < ActionView::TestCase
tests TabsOnRails::ActionController::HelperMethods

include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper

def current_tab(namespace)
case namespace
when nil, :default
:dashboard
when :foospace
:footab
else
:elsetab
end
end


def setup
@klass = TabsOnRails::Tabs::TabsBuilder
@builder = @klass.new(self)
@builder = TabsOnRails::Tabs::TabsBuilder.new(self)
end

def test_should_extend_builder
assert_equal TabsOnRails::Tabs::Builder, @klass.superclass
def test_inherits_from_builder
assert_equal TabsOnRails::Tabs::Builder, TabsOnRails::Tabs::TabsBuilder.superclass
end


Expand Down
31 changes: 7 additions & 24 deletions test/unit/tabs_test.rb
@@ -1,22 +1,6 @@
require 'test_helper'

class TabsTest < ActiveSupport::TestCase

Template = Class.new do
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper

def current_tab(namespace)
case namespace
when nil, :default
:dashboard
when :foospace
:footab
else
:elsetab
end
end
end
class TabsTest < ActionView::TestCase

OpenZeroArgsBuilder = Class.new(TabsOnRails::Tabs::Builder) do
def open_tabs
Expand All @@ -41,21 +25,20 @@ def tab_for(tab, name, options, item_options = {}, &block)


def setup
@template = Template.new
@klass = TabsOnRails::Tabs
@tabs = @klass.new(@template)
@template = self
@tabs = TabsOnRails::Tabs.new(@template)
end


def test_initialize
@tabs = @klass.new(@template)
@tabs = TabsOnRails::Tabs.new(@template)
assert_equal @template, @tabs.instance_variable_get(:"@context")
assert_instance_of TabsOnRails::Tabs::TabsBuilder, @tabs.instance_variable_get(:"@builder")
end

def test_initialize_with_option_builder
builder = Class.new(TabsOnRails::Tabs::TabsBuilder)
@tabs = @klass.new(@template, :builder => builder)
@tabs = TabsOnRails::Tabs.new(@template, :builder => builder)
assert_equal @template, @tabs.instance_variable_get(:"@context")
assert_instance_of builder, @tabs.instance_variable_get(:"@builder")
end
Expand All @@ -70,7 +53,7 @@ def test_open_tabs_with_options
end

def test_open_tabs_should_ignore_options_if_arity_is_zero
@tabs = @klass.new(@template, :builder => OpenZeroArgsBuilder)
@tabs = TabsOnRails::Tabs.new(@template, :builder => OpenZeroArgsBuilder)
assert_nothing_raised do
assert_equal '<ul>', @tabs.open_tabs(:class => "foo")
end
Expand All @@ -86,7 +69,7 @@ def test_close_tabs_with_options
end

def test_open_tabs_should_ignore_options_if_arity_is_zero
@tabs = @klass.new(@template, :builder => CloseZeroArgsBuilder)
@tabs = TabsOnRails::Tabs.new(@template, :builder => CloseZeroArgsBuilder)
assert_nothing_raised do
assert_equal '</ul>', @tabs.close_tabs(:class => "foo")
end
Expand Down

0 comments on commit c7a3de0

Please sign in to comment.