Skip to content

Commit

Permalink
Use Minitest
Browse files Browse the repository at this point in the history
* Replace Test::Unit with a newer version of mintiest.
* Primary reason: Nested describe contexts should make test intent clearer.
  • Loading branch information
peakpg committed Mar 19, 2013
1 parent c309693 commit e32c895
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 48 deletions.
18 changes: 14 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@ group :assets do
gem 'bootstrap-sass'
end


group :development do
gem 'rake', '~> 0.9.5'
end
group :test, :development do
gem 'minitest'
gem 'minitest-rails'
#gem 'minitest-reporters'
end

group :test do
gem 'm', '~> 1.2'

gem 'factory_girl_rails', '3.3.0'
gem 'test-unit', '2.1.1'
# :require=>false allows mocha to correctly modify the test:unit code to add mock() and stub()
gem "mocha", '=0.9.8', :require=>false
gem "mocha"
gem "sqlite3-ruby", :require => "sqlite3"

# Cucumber and dependencies
gem 'capybara'
gem 'capybara', '~>1.1'
gem 'database_cleaner'
gem 'cucumber-rails', require: false
gem 'cucumber'
Expand Down
35 changes: 23 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ GEM
bootstrap-sass (2.2.1.1)
sass (~> 3.2)
builder (3.0.4)
capybara (2.0.0)
capybara (1.1.3)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 1.0.0)
xpath (~> 0.1.4)
childprocess (0.3.6)
ffi (~> 1.0, >= 1.0.6)
ckeditor_rails (3.6.4.1)
Expand Down Expand Up @@ -95,7 +95,7 @@ GEM
factory_girl_rails (3.3.0)
factory_girl (~> 3.3.0)
railties (>= 3.0.0)
ffi (1.1.5)
ffi (1.2.0)
gherkin (2.11.5)
json (>= 1.4.6)
hike (1.2.1)
Expand All @@ -107,18 +107,27 @@ GEM
json (1.7.5)
launchy (2.1.2)
addressable (~> 2.3)
libwebsocket (0.1.6)
libwebsocket (0.1.6.1)
websocket
m (1.2.1)
method_source (>= 0.6.7)
rake (>= 0.9.2.2, < 1.0.0)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mercury-rails (0.9.0)
coffee-rails
railties (~> 3.2)
metaclass (0.0.1)
method_source (0.8.1)
mime-types (1.19)
mocha (0.9.8)
rake
minitest (4.3.0)
minitest-rails (0.3)
minitest (~> 4.0)
rails (~> 3.0)
mocha (0.13.0)
metaclass (~> 0.0.1)
multi_json (1.3.7)
mysql2 (0.3.11)
nokogiri (1.5.5)
Expand Down Expand Up @@ -151,7 +160,7 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.0.2)
rake (0.9.5)
rdoc (3.12)
json (~> 1.4)
rspec (2.12.0)
Expand Down Expand Up @@ -183,7 +192,6 @@ GEM
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
term-ansicolor (1.0.7)
test-unit (2.1.1)
thin (1.5.0)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
Expand All @@ -198,7 +206,7 @@ GEM
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
websocket (1.0.3)
xpath (1.0.0)
xpath (0.1.4)
nokogiri (~> 1.3)
yard (0.8.3)

Expand All @@ -210,19 +218,22 @@ DEPENDENCIES
bluecloth
bootstrap-sass
browsercms!
capybara
capybara (~> 1.1)
cucumber
cucumber-rails
database_cleaner
factory_girl_rails (= 3.3.0)
launchy
m (~> 1.2)
mercury-rails
mocha (= 0.9.8)
minitest
minitest-rails
mocha
mysql2
rake (~> 0.9.5)
ruby-prof
sass-rails
sqlite3-ruby
test-unit (= 2.1.1)
thin
uglifier
yard
1 change: 1 addition & 0 deletions app/views/layouts/cms/_thin_toolbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<ul class="nav">
<li class="dropdown">
<a href="#">
<%# This nested li syntax causes functional tests to fail. (i.e. ignoring attempt to close li with div) %>
<%= nav_link_to image_tag("cms/home.png"), "/" %>
</a>
<ul class="dropdown-menu">
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/user_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
end

Then /^I should be denied access$/ do
assert 403, page.status_code
assert_equal 403, page.status_code
end

Given /^I have a content editor account$/ do
Expand Down
2 changes: 1 addition & 1 deletion features/support/page_inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def page_should_have_content(content, should_be_true=true)
end

def should_see_a_page_titled(page_title)
assert page.has_css?("title", :text => page_title), "Expected a page with a title '#{page_title}'."
assert page.has_content?(page_title)
assert page.has_css?("title", :text => page_title), "Expected a page with a title '#{page_title}'."
end

def should_see_cms_404_page
Expand Down
6 changes: 3 additions & 3 deletions test/custom_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def assert_column_does_not_exist(table_name, column_name)
end

# Remove for Ruby 1.9.2/Minitest
def refute(value, msg=nil)
assert !value, msg
end
#def refute(value, msg=nil)
# assert !value, msg
#end

def assert_file_exists(file_name, message=nil)
assert File.exists?(file_name),
Expand Down
3 changes: 0 additions & 3 deletions test/functional/cms/content_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ def test_cms_user_views_page_on_cms_site_with_caching

assert_response :success
assert_select "title", "Test Page"
assert_select "iframe"
end

end
Expand Down Expand Up @@ -289,7 +288,6 @@ def test_cms_user_views_page_on_public_site

assert_response :success
assert_select "title", "Test Page"
assert_select "iframe"
end

def test_cms_user_views_page_on_cms_site
Expand All @@ -301,7 +299,6 @@ def test_cms_user_views_page_on_cms_site

assert_response :success
assert_select "title", "Test Page"
assert_select "iframe"
end

test "When portlets throw a generic error, the page should still render the other content." do
Expand Down
28 changes: 28 additions & 0 deletions test/minitest_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment.rb", __FILE__)

require "minitest/autorun"
require "minitest/rails"

#require 'minitest/reporters'
#MiniTest::Reporters.use!

# Uncomment if you want Capybara in accceptance/integration tests
# require "minitest/rails/capybara"

# Uncomment if you want awesome colorful output
# require "minitest/pride"

class MiniTest::Rails::ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
fixtures :all

# Add more helper methods to be used by all tests here...
end

# Do you want all existing Rails tests to use MiniTest::Rails?
# Comment out the following and either:
# A) Change the require on the existing tests to `require "minitest_helper"`
# B) Require this file's code in test_helper.rb

#MiniTest::Rails.override_testunit!
32 changes: 15 additions & 17 deletions test/unit/behaviors/mercury_editor_test.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
require "test_helper"
require 'minitest_helper'

class MecuryEditorTest < ActiveSupport::TestCase
describe "MercuryEditor" do

test "#editor_type_for Text Areas" do
field_info = Cms::HtmlBlock.new.editor_info(:content)
assert_equal "full", field_info[:region]
assert_equal "div", field_info[:element]
end
describe "#editor_info" do

test "#editor_type_for text fields" do
field_info = content_block().editor_info(:name)
assert_equal "simple", field_info[:region]
assert_equal "span", field_info[:element]
end
let(:content_block) { Cms::HtmlBlock.new }

private
it "returns full for text area fields" do
field_info = content_block.editor_info(:content)
field_info[:region].must_equal "full"
field_info[:element].must_equal "div"
end

# Factory for a simple content block.
def content_block
Cms::HtmlBlock.new
it "returns simple region for text fields" do
field_info = content_block.editor_info(:name)
field_info[:region].must_equal "simple"
field_info[:element].must_equal "span"
end
end
end
end
2 changes: 1 addition & 1 deletion test/unit/lib/acts_as_content_page_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "test_helper"
require "mocha"
require "mocha/setup"

class CmsActsAsContentPageTest < ActiveSupport::TestCase
EXPECTED_SECTION = "/members"
Expand Down
1 change: 0 additions & 1 deletion test/unit/lib/cms/authentication/controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "test_helper"
require 'mocha'

class ProtectedController < ActionController::Base
include Cms::Authentication::Controller
Expand Down
2 changes: 0 additions & 2 deletions test/unit/lib/cms_domain_support_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require 'test_helper'

require 'mocha'

class CmsDomainSupportTest < ActiveSupport::TestCase

def setup
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/command_line_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "test_helper"
require "mocha"
require "mocha/setup"

class CommandLineTest < ActiveSupport::TestCase

Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/content_block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_editing_connected_to_an_unpublished_page
assert @block.update_attributes(:name => "something different")
reset(:page)

assert 2, @page.version
assert_equal 1, @page.version
assert_equal page_version_count, Cms::Page::Version.count
assert !@page.published?

Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/html_block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_reverting
assert_equal @v1_created_at.to_i, @html_block.find_version(1).created_at.to_i
assert_equal @v2_created_at.to_i, @html_block.find_version(2).created_at.to_i
assert @html_block.find_version(3).created_at.to_i >= @v2_created_at.to_i
assert @v1_created_at.to_i, @html_block.created_at.to_i
assert_equal @v1_created_at.to_i, @html_block.created_at.to_i

# version is required for revert_to
html_block_version_count = Cms::HtmlBlock::Version.count
Expand Down

0 comments on commit e32c895

Please sign in to comment.