Skip to content

Commit

Permalink
moved tests to MiniTest::Spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodacious committed Nov 6, 2011
1 parent d2cc675 commit ca4e5df
Show file tree
Hide file tree
Showing 51 changed files with 220 additions and 89 deletions.
7 changes: 5 additions & 2 deletions Gemfile
Expand Up @@ -9,6 +9,9 @@ gemspec
gem "jquery-rails"
gem "sass-rails"
gem "guard"
gem "guard-test"
gem "guard-minitest"
gem "growl"
gem "yard"
gem "yard"
gem "rb-fsevent"
gem "minitest-rails"
gem "nokogiri"
19 changes: 14 additions & 5 deletions Gemfile.lock
Expand Up @@ -41,9 +41,8 @@ GEM
growl (1.0.3)
guard (0.8.8)
thor (~> 0.14.6)
guard-test (0.4.1)
guard (>= 0.4)
test-unit (~> 2.2)
guard-minitest (0.4.0)
guard (~> 0.4)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.16)
Expand All @@ -55,7 +54,14 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
minitest (2.7.0)
minitest-rails (0.0.5)
actionpack (~> 3.1.0.rc1)
activesupport (~> 3.1.0.rc1)
minitest (~> 2.2)
railties (~> 3.1.0.rc1)
multi_json (1.0.3)
nokogiri (1.5.0)
polyglot (0.3.3)
rack (1.3.5)
rack-cache (1.1)
Expand All @@ -82,6 +88,7 @@ GEM
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rb-fsevent (0.4.3.1)
rdoc (3.11)
json (~> 1.4)
sass (3.1.10)
Expand All @@ -96,7 +103,6 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.4)
test-unit (2.4.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
Expand All @@ -112,8 +118,11 @@ DEPENDENCIES
box_of_tricks!
growl
guard
guard-test
guard-minitest
jquery-rails
minitest-rails
nokogiri
rb-fsevent
sass-rails
sqlite3
yard
21 changes: 7 additions & 14 deletions Guardfile
@@ -1,15 +1,8 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard :test do
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
watch(%r{^test/.+_test\.rb$})
watch('test/test_helper.rb') { "test" }

# Rails example
watch(%r{^app/models/(.+)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
watch(%r{^app/controllers/(.+)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
watch(%r{^app/helpers/(.+)\.rb$}) { |m| "test/unit/helpers/#{m[1]}_test.rb" }
watch(%r{^app/views/.+\.rb$}) { "test/integration" }
watch('app/controllers/application_controller.rb') { ["test/functional", "test/integration"] }
guard :minitest do
# with Minitest::Spec
watch(%r|^spec/(.*)_spec\.rb|)
watch(%r|^app/(.*)\.rb|) { |m| "spec/#{m[1]}_spec.rb" }

watch(%r|^lib/(.*)\.rb|) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r|^spec/spec_helper\.rb|) { "rake test" }
end
10 changes: 5 additions & 5 deletions Rakefile
Expand Up @@ -20,19 +20,19 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'


Bundler::GemHelper.install_tasks

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
Rake::TestTask.new(:spec) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
t.libs << 'spec'
t.pattern = 'spec/**/*_spec.rb'
t.verbose = true
end


Expand Down
2 changes: 1 addition & 1 deletion app/helpers/box_of_tricks_helper.rb
Expand Up @@ -17,7 +17,7 @@ module BoxOfTricksHelper
# Content may be passed as a block or as the first argument
# @author Gavin Morrice
def title(content = nil)
content ? @content = content : @content
content ? @title = content : @title
end

# Creates a div with class 'field'. All of the usual options may also be applied
Expand Down
2 changes: 1 addition & 1 deletion script/rails
Expand Up @@ -3,4 +3,4 @@
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

ENGINE_PATH = File.expand_path('../..', __FILE__)
load File.expand_path('../../test/dummy/script/rails', __FILE__)
load File.expand_path('../../spec/dummy/script/rails', __FILE__)
2 changes: 1 addition & 1 deletion test/box_of_tricks_test.rb → spec/box_of_tricks_spec.rb
@@ -1,4 +1,4 @@
require 'test_helper'
require 'spec_helper'

class BoxOfTricksTest < ActiveSupport::TestCase

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added spec/dummy/public/favicon.ico
Empty file.
File renamed without changes.
160 changes: 160 additions & 0 deletions spec/helpers/box_of_tricks_helper_spec.rb
@@ -0,0 +1,160 @@
require 'spec_helper'


describe BoxOfTricksHelper do

describe :title do

it "should set the title if passed an arguement" do
helper.title("HelloWorld")
helper.instance_variable_get("@title").must_equal "HelloWorld"
end

it "should return the title if called without an argument" do
helper.title("HelloWorld")
helper.title.must_equal "HelloWorld"
end

end

describe :field do

it "should return a div with class 'field'" do
helper.field("").must_equal "<div class=\"field\"></div>"
end

it "should accept content as an argument" do
helper.field("hello").must_equal "<div class=\"field\">hello</div>"
end

it "should accept content as a block" do
helper.field { "hello" }.must_equal "<div class=\"field\">hello</div>"
end

it "should accept options for class, id and data" do
helper.field("hello", id: "my_field", class: "other", data: {url: "/"}).
must_be_dom_equal "<div class=\"other field\" id=\"my_field\" data-url=\"/\">hello</div>"
helper.field(id: "my_field", class: "other", data: {url: "/"}) { "hello" }.
must_be_dom_equal "<div class=\"other field\" id=\"my_field\" data-url=\"/\">hello</div>"
end

end

describe :actions do

it "should return a div with class 'actions'" do
helper.actions("").must_equal "<div class=\"actions\"></div>"
end

it "should accept content as an argument" do
helper.actions("hello").must_equal "<div class=\"actions\">hello</div>"
end

it "should accept content as a block" do
helper.actions { "hello" }.must_equal "<div class=\"actions\">hello</div>"
end

it "should accept options for class, id and data" do
helper.actions("hello", id: "my_field", class: "other", data: {url: "/"}).
must_be_dom_equal "<div class=\"other actions\" id=\"my_field\" data-url=\"/\">hello</div>"
helper.actions(id: "my_field", class: "other", data: {url: "/"}) { "hello" }.
must_be_dom_equal "<div class=\"other actions\" id=\"my_field\" data-url=\"/\">hello</div>"
end

end

describe :html5_shim do

it "should add a conditional comment to the dom with script tag" do
helper.html5_shim.must_be_dom_equal %{<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->}
end

end

describe :clearfix do

it "it should add a br tag with class 'clear'" do
helper.clearfix.must_be_dom_equal %{<br class="clear">}
end

end

describe :div do

it "should accept content as an argument" do
helper.div("bodacious").must_be_dom_equal %{<div>bodacious</div>}
end

it "should accept content as a block" do
helper.div {"bodacious"}.must_be_dom_equal %{<div>bodacious</div>}
end

it "should accept options for attributes" do
helper.div("hello", id: "my_field", class: "other").
must_be_dom_equal "<div class=\"other\" id=\"my_field\">hello</div>"

helper.div(id: "my_field", class: "other") { "hello" }.
must_be_dom_equal "<div class=\"other\" id=\"my_field\">hello</div>"
end
end

end

# class BoxOfTricksHelperTest < ActionView::TestCase
#
# test "title" do
# title("Set Title")
# assert_equal title, "Set Title"
# end
#
# test "div_with_class" do
# assert_dom_equal %{<div class="user">Bodacious</div>},
# div_with_class(:user, "Bodacious")
#
# assert_dom_equal %{<div class="admin user">Bodacious</div>},
# div_with_class(:user, "Bodacious", class: "admin")
#
# assert_dom_equal %{<div class="admin user" id="user_1">Bodacious</div>},
# div_with_class(:user, "Bodacious", class: "admin", id: "user_1")
#
# assert_dom_equal %{<div class="admin user" id="user_1">Bodacious</div>},
# div_with_class(:user, class: "admin", id: "user_1") { "Bodacious" }
# end
#
# test "field" do
# assert_dom_equal %{<div class="field"><p>hello</p></div>},
# field { content_tag(:p, "hello") }
#
# assert_dom_equal %{<div class="field"><p>hello</p></div>},
# field(content_tag(:p, "hello"))
# end
#
# test "actions" do
# assert_dom_equal %{<div class="actions">hello</div>},
# actions { "hello" }
#
# assert_dom_equal %{<div class="actions">hello</div>},
# actions("hello")
# end
#
# test "div" do
# assert_dom_equal %{<div>hello</div>},
# div("hello")
#
# assert_dom_equal %{<div class="spaniel" id="hello_div" data-url="/">hello</div>},
# div("hello", class: "spaniel", id: "hello_div", data: {url: "/"})
#
# assert_dom_equal %{<div class="muppet">Muppet 1</div>},
# div(class: "muppet") { "Muppet 1" }
# end
#
# test "html5_shim" do
# assert_dom_equal %{<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->},
# html5_shim
# end
#
# test "clearfix" do
# assert_dom_equal %{<br class="clear">}, clearfix
# end
#
# end
3 changes: 3 additions & 0 deletions test/test_helper.rb → spec/spec_helper.rb
Expand Up @@ -2,8 +2,11 @@
ENV["RAILS_ENV"] = "test"

require File.expand_path("../dummy/config/environment.rb", __FILE__)

require "rails/test_help"

require "minitest/rails"

Rails.backtrace_cleaner.remove_silencers!

# Load support files
Expand Down
5 changes: 5 additions & 0 deletions spec/support/dummy_view.rb
@@ -0,0 +1,5 @@
class DummyView < ActionView::Base

include BoxOfTricksHelper

end
3 changes: 3 additions & 0 deletions spec/support/helper_methods.rb
@@ -0,0 +1,3 @@
def helper
@helper ||= DummyView.new
end
5 changes: 5 additions & 0 deletions spec/support/minitest/expectations.rb
@@ -0,0 +1,5 @@
module MiniTest::Expectations

infect_an_assertion :assert_dom_equal, :must_be_dom_equal, :reverse

end
10 changes: 10 additions & 0 deletions spec/support/minitest/matchers.rb
@@ -0,0 +1,10 @@
module MiniTest::Assertions

def assert_dom_equal(expected, actual, message = nil)
expected_dom = HTML::Document.new(expected).root
actual_dom = HTML::Document.new(actual).root
message = "expected:\n #{actual}\nto equal:\n#{expected}"
assert_block(message) { expected_dom == actual_dom }
end

end

0 comments on commit ca4e5df

Please sign in to comment.