Permalink
Browse files

Upgrade tests to Rails 3

  • Loading branch information...
1 parent b1a87b8 commit 4c7e7efb678daff3dffaab0910918bc48839c495 @weppos committed Apr 6, 2011
View
3 Gemfile
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+
+gemspec
View
14 Gemfile.lock
@@ -0,0 +1,14 @@
+PATH
+ remote: .
+ specs:
+ breadcrumbs_on_rails (1.0.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ breadcrumbs_on_rails!
View
92 Rakefile
@@ -1,76 +1,52 @@
-require "rubygems"
-require "rake/testtask"
-require "rake/gempackagetask"
-begin
- require "hanna/rdoctask"
-rescue LoadError
- require "rake/rdoctask"
-end
+require 'rubygems'
+require 'bundler'
+require 'rake/testtask'
+require 'rake/gempackagetask'
+require 'hanna/rdoctask'
$:.unshift(File.dirname(__FILE__) + "/lib")
-require "breadcrumbs_on_rails"
+require 'breadcrumbs_on_rails/version'
-PKG_NAME = ENV['PKG_NAME'] || BreadcrumbsOnRails::GEM
+PKG_NAME = ENV['PKG_NAME'] || "breadcrumbs_on_rails"
PKG_VERSION = ENV['PKG_VERSION'] || BreadcrumbsOnRails::VERSION
if ENV['SNAPSHOT'].to_i == 1
PKG_VERSION << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
end
-# Run all the tests in the /test folder
-Rake::TestTask.new do |t|
- t.libs << "test"
- t.test_files = FileList["test/**/*_test.rb"]
- t.verbose = true
-end
-
-# Generate documentation
-Rake::RDocTask.new do |rd|
- rd.main = "README.rdoc"
- rd.rdoc_files.include("*.rdoc", "lib/**/*.rb")
- rd.rdoc_dir = "rdoc"
-end
-
# Run test by default.
-task :default => ["test"]
+task :default => :test
# This builds the actual gem. For details of what all these options
# mean, and other ones you can add, check the documentation here:
#
# http://rubygems.org/read/chapter/20
#
spec = Gem::Specification.new do |s|
-
s.name = PKG_NAME
s.version = PKG_VERSION
s.summary = "A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation."
+ s.description = "BreadcrumbsOnRails is a simple Ruby on Rails plugin for creating and managing a breadcrumb navigation for a Rails project."
+
s.author = "Simone Carletti"
s.email = "weppos@weppos.net"
s.homepage = "http://www.simonecarletti.com/code/breadcrumbs_on_rails"
- s.description = <<-EOD
- BreadcrumbsOnRails is a simple Ruby on Rails plugin for creating and managing \
- a breadcrumb navigation for a Rails project. \
- It provides helpers for creating navigation elements with a flexible interface.
- EOD
- s.has_rdoc = true
# You should probably have a README of some kind. Change the filename
# as appropriate
s.extra_rdoc_files = Dir.glob("*.rdoc")
- s.rdoc_options = %w(--main README.rdoc)
+ s.rdoc_options = %w( --main README.rdoc )
# Add any extra files to include in the gem (like your README)
- s.files = %w(Rakefile init.rb) + Dir.glob("*.{rdoc,gemspec}") + Dir.glob("{test,lib,rails}/**/*")
- s.require_paths = ["lib"]
-
- # If you want to depend on other gems, add them here, along with any
- # relevant versions
- # s.add_dependency("some_other_gem", "~> 0.1.0")
+ s.files = %w( Rakefile LICENSE init.rb ) + Dir.glob("*.{rdoc,gemspec}") + Dir.glob("{lib,test,rails}/**/*")
+ s.require_paths = %w( lib )
- # If your tests use any gems, include them here
- # s.add_development_dependency("mocha") # for example
+ s.add_development_dependency("bundler")
+ s.add_development_dependency("hanna")
+ s.add_development_dependency("rails", "~> 3.0.6")
+ s.add_development_dependency("mocha", "~> 0.9.10")
end
# This task actually builds the gem. We also regenerate a static
@@ -98,32 +74,22 @@ task :clobber => [:clobber_rdoc, :clobber_rcov, :clobber_package]
desc "Package the library and generates the gemspec"
task :package => [:gemspec]
-begin
- require "rcov/rcovtask"
-
- desc "Create a code coverage report."
- Rcov::RcovTask.new do |t|
- t.test_files = FileList["test/**/*_test.rb"]
- t.ruby_opts << "-Itest -x mocha,rcov,Rakefile"
- t.verbose = true
- end
-rescue LoadError
- task :clobber_rcov
- puts "RCov is not available"
-end
-begin
- require "code_statistics"
+# Run all the tests in the /test folder
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList["test/**/*_test.rb"]
+ t.verbose = true
+end
- desc "Show library's code statistics"
- task :stats do
- CodeStatistics.new(["BreadcrumbsOnRails", "lib"],
- ["Tests", "test"]).to_s
- end
-rescue LoadError
- puts "CodeStatistics (Rails) is not available"
+# Generate documentation
+Rake::RDocTask.new do |rd|
+ rd.main = "README.rdoc"
+ rd.rdoc_files.include("*.rdoc", "lib/**/*.rb")
+ rd.rdoc_dir = "rdoc"
end
+
desc "Publish documentation to the site"
task :publish_rdoc => [:clobber_rdoc, :rdoc] do
ENV["username"] || raise(ArgumentError, "Missing ssh username")
View
26 breadcrumbs_on_rails.gemspec
@@ -6,25 +6,35 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Simone Carletti"]
- s.date = %q{2010-05-11}
- s.description = %q{ BreadcrumbsOnRails is a simple Ruby on Rails plugin for creating and managing a breadcrumb navigation for a Rails project. It provides helpers for creating navigation elements with a flexible interface.
-}
+ s.date = %q{2011-04-07}
+ s.description = %q{BreadcrumbsOnRails is a simple Ruby on Rails plugin for creating and managing a breadcrumb navigation for a Rails project.}
s.email = %q{weppos@weppos.net}
- s.extra_rdoc_files = ["CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc"]
- s.files = ["Rakefile", "init.rb", "CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc", "rails/init.rb"]
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc"]
+ s.files = ["Rakefile", "LICENSE", "init.rb", "CHANGELOG.rdoc", "README.rdoc", "breadcrumbs_on_rails.gemspec", "lib/breadcrumbs_on_rails", "lib/breadcrumbs_on_rails/breadcrumbs.rb", "lib/breadcrumbs_on_rails/controller_mixin.rb", "lib/breadcrumbs_on_rails/railtie.rb", "lib/breadcrumbs_on_rails/version.rb", "lib/breadcrumbs_on_rails.rb", "test/test_helper.rb", "test/unit", "test/unit/breadcrumbs_on_rails_test.rb", "test/unit/builder_test.rb", "test/unit/element_test.rb", "test/unit/simple_builder_test.rb"]
s.homepage = %q{http://www.simonecarletti.com/code/breadcrumbs_on_rails}
s.rdoc_options = ["--main", "README.rdoc"]
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.6}
+ s.rubygems_version = %q{1.6.1}
s.summary = %q{A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation.}
if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<bundler>, [">= 0"])
+ s.add_development_dependency(%q<hanna>, [">= 0"])
+ s.add_development_dependency(%q<rails>, ["~> 3.0.6"])
+ s.add_development_dependency(%q<mocha>, ["~> 0.9.10"])
else
+ s.add_dependency(%q<bundler>, [">= 0"])
+ s.add_dependency(%q<hanna>, [">= 0"])
+ s.add_dependency(%q<rails>, ["~> 3.0.6"])
+ s.add_dependency(%q<mocha>, ["~> 0.9.10"])
end
else
+ s.add_dependency(%q<bundler>, [">= 0"])
+ s.add_dependency(%q<hanna>, [">= 0"])
+ s.add_dependency(%q<rails>, ["~> 3.0.6"])
+ s.add_dependency(%q<mocha>, ["~> 0.9.10"])
end
end
View
14 lib/breadcrumbs_on_rails/controller_mixin.rb
@@ -17,15 +17,13 @@
module BreadcrumbsOnRails
module ControllerMixin
+ extend ActiveSupport::Concern
- def self.included(base)
- base.extend ClassMethods
- base.send :helper, HelperMethods
- base.class_eval do
- include InstanceMethods
- helper HelperMethods
- helper_method :add_breadcrumb, :breadcrumbs
- end
+ included do
+ extend ClassMethods
+ include InstanceMethods
+ helper HelperMethods
+ helper_method :add_breadcrumb, :breadcrumbs
end
module Utils
View
6 lib/breadcrumbs_on_rails/railtie.rb
@@ -17,8 +17,12 @@
module BreadcrumbsOnRails
class Railtie < Rails::Railtie
+ initializer "breadcrumbs_on_rails.initialize" do
+ end
end
end
-ActionController::Base.send :include, BreadcrumbsOnRails::ControllerMixin
+ActiveSupport.on_load(:action_controller) do
+ include BreadcrumbsOnRails::ControllerMixin
+end
View
33 test/test_helper.rb
@@ -1,23 +1,20 @@
-require 'rubygems'
-gem 'rails', '~>2.3.0'
-gem 'mocha', '~>0.9.7'
+require 'test/unit'
+require 'mocha'
-# Remember! Due to some Mocha internal changes,
-# Rails 2.2.x requires Mocha 0.9.5 and
-# Rails 2.3.x requires Mocha 0.9.7
-# gem 'rails', '2.2.2'
-# gem 'mocha', '0.9.5'
+ENV["RAILS_ENV"] = "test"
-require 'test/unit'
-require 'active_support'
-require 'action_controller'
-require 'action_view/test_case'
+require "active_support"
+require "action_controller"
+require "rails/railtie"
+
+$:.unshift File.expand_path('../../lib', __FILE__)
+require 'breadcrumbs_on_rails'
-$:.unshift File.dirname(__FILE__) + '/../lib'
-require File.dirname(__FILE__) + '/../init.rb'
+ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
-RAILS_ROOT = '.' unless defined? RAILS_ROOT
-RAILS_ENV = 'test' unless defined? RAILS_ENV
+BreadcrumbsOnRails::Routes = ActionDispatch::Routing::RouteSet.new
+BreadcrumbsOnRails::Routes.draw do
+ match ':controller(/:action(/:id))'
+end
-ActionController::Base.logger = nil
-ActionController::Routing::Routes.reload rescue nil
+ActionController::Base.send :include, BreadcrumbsOnRails::Routes.url_helpers
View
0 test/breadcrumbs_on_rails_test.rb → test/unit/breadcrumbs_on_rails_test.rb
File renamed without changes.
View
7 test/builder_test.rb → test/unit/builder_test.rb
@@ -1,9 +1,8 @@
require 'test_helper'
-
class BuilderTest < ActiveSupport::TestCase
- class TestTemplate
+ Template = Class.new do
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
@@ -28,12 +27,10 @@ def method_for_path
def proc_for_path
"http://localhost/#proc"
end
-
end
-
def setup
- @template = TestTemplate.new
+ @template = Template.new
@element = BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, nil)
end
View
0 test/element_test.rb → test/unit/element_test.rb
File renamed without changes.
View
6 test/simple_builder_test.rb → test/unit/simple_builder_test.rb
@@ -3,14 +3,13 @@
class SimpleBuilderTest < ActionView::TestCase
- class TestTemplate
+ Template = Class.new do
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
end
-
def setup
- @template = TestTemplate.new
+ @template = Template.new
end
def test_render_should_be_implemented
@@ -71,5 +70,4 @@ def generate_elements(number)
end
end
-
end

0 comments on commit 4c7e7ef

Please sign in to comment.