diff --git a/Gemfile b/Gemfile index b6c2bb1..bb57462 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,9 @@ gemspec gem "jquery-rails" gem "sass-rails" gem "guard" -gem "guard-test" +gem "guard-minitest" gem "growl" -gem "yard" \ No newline at end of file +gem "yard" +gem "rb-fsevent" +gem "minitest-rails" +gem "nokogiri" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index d868c3e..296ad90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/Guardfile b/Guardfile index 9df4de5..ff89fb8 100644 --- a/Guardfile +++ b/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 diff --git a/Rakefile b/Rakefile index 3da09e2..4ab38bf 100644 --- a/Rakefile +++ b/Rakefile @@ -20,7 +20,7 @@ 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' @@ -28,11 +28,11 @@ 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 diff --git a/app/helpers/box_of_tricks_helper.rb b/app/helpers/box_of_tricks_helper.rb index 896a7bc..777f1f8 100644 --- a/app/helpers/box_of_tricks_helper.rb +++ b/app/helpers/box_of_tricks_helper.rb @@ -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 diff --git a/script/rails b/script/rails index e323e44..4309856 100755 --- a/script/rails +++ b/script/rails @@ -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__) diff --git a/test/box_of_tricks_test.rb b/spec/box_of_tricks_spec.rb similarity index 71% rename from test/box_of_tricks_test.rb rename to spec/box_of_tricks_spec.rb index 3615799..7130c99 100644 --- a/test/box_of_tricks_test.rb +++ b/spec/box_of_tricks_spec.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require 'spec_helper' class BoxOfTricksTest < ActiveSupport::TestCase diff --git a/test/dummy/Rakefile b/spec/dummy/Rakefile similarity index 100% rename from test/dummy/Rakefile rename to spec/dummy/Rakefile diff --git a/test/dummy/app/assets/javascripts/application.js b/spec/dummy/app/assets/javascripts/application.js similarity index 100% rename from test/dummy/app/assets/javascripts/application.js rename to spec/dummy/app/assets/javascripts/application.js diff --git a/test/dummy/app/assets/javascripts/homepage.js b/spec/dummy/app/assets/javascripts/homepage.js similarity index 100% rename from test/dummy/app/assets/javascripts/homepage.js rename to spec/dummy/app/assets/javascripts/homepage.js diff --git a/test/dummy/app/assets/stylesheets/application.css b/spec/dummy/app/assets/stylesheets/application.css similarity index 100% rename from test/dummy/app/assets/stylesheets/application.css rename to spec/dummy/app/assets/stylesheets/application.css diff --git a/test/dummy/app/assets/stylesheets/homepage.css.scss b/spec/dummy/app/assets/stylesheets/homepage.css.scss similarity index 100% rename from test/dummy/app/assets/stylesheets/homepage.css.scss rename to spec/dummy/app/assets/stylesheets/homepage.css.scss diff --git a/test/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb similarity index 100% rename from test/dummy/app/controllers/application_controller.rb rename to spec/dummy/app/controllers/application_controller.rb diff --git a/test/dummy/app/controllers/homepage_controller.rb b/spec/dummy/app/controllers/homepage_controller.rb similarity index 100% rename from test/dummy/app/controllers/homepage_controller.rb rename to spec/dummy/app/controllers/homepage_controller.rb diff --git a/test/dummy/app/helpers/application_helper.rb b/spec/dummy/app/helpers/application_helper.rb similarity index 100% rename from test/dummy/app/helpers/application_helper.rb rename to spec/dummy/app/helpers/application_helper.rb diff --git a/test/dummy/app/helpers/homepage_helper.rb b/spec/dummy/app/helpers/homepage_helper.rb similarity index 100% rename from test/dummy/app/helpers/homepage_helper.rb rename to spec/dummy/app/helpers/homepage_helper.rb diff --git a/test/dummy/app/mailers/.gitkeep b/spec/dummy/app/mailers/.gitkeep similarity index 100% rename from test/dummy/app/mailers/.gitkeep rename to spec/dummy/app/mailers/.gitkeep diff --git a/test/dummy/app/models/.gitkeep b/spec/dummy/app/models/.gitkeep similarity index 100% rename from test/dummy/app/models/.gitkeep rename to spec/dummy/app/models/.gitkeep diff --git a/test/dummy/app/views/homepage/show.html.erb b/spec/dummy/app/views/homepage/show.html.erb similarity index 100% rename from test/dummy/app/views/homepage/show.html.erb rename to spec/dummy/app/views/homepage/show.html.erb diff --git a/test/dummy/app/views/layouts/application.html.erb b/spec/dummy/app/views/layouts/application.html.erb similarity index 100% rename from test/dummy/app/views/layouts/application.html.erb rename to spec/dummy/app/views/layouts/application.html.erb diff --git a/test/dummy/config.ru b/spec/dummy/config.ru similarity index 100% rename from test/dummy/config.ru rename to spec/dummy/config.ru diff --git a/test/dummy/config/application.rb b/spec/dummy/config/application.rb similarity index 100% rename from test/dummy/config/application.rb rename to spec/dummy/config/application.rb diff --git a/test/dummy/config/boot.rb b/spec/dummy/config/boot.rb similarity index 100% rename from test/dummy/config/boot.rb rename to spec/dummy/config/boot.rb diff --git a/test/dummy/config/database.yml b/spec/dummy/config/database.yml similarity index 100% rename from test/dummy/config/database.yml rename to spec/dummy/config/database.yml diff --git a/test/dummy/config/environment.rb b/spec/dummy/config/environment.rb similarity index 100% rename from test/dummy/config/environment.rb rename to spec/dummy/config/environment.rb diff --git a/test/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb similarity index 100% rename from test/dummy/config/environments/development.rb rename to spec/dummy/config/environments/development.rb diff --git a/test/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb similarity index 100% rename from test/dummy/config/environments/production.rb rename to spec/dummy/config/environments/production.rb diff --git a/test/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb similarity index 100% rename from test/dummy/config/environments/test.rb rename to spec/dummy/config/environments/test.rb diff --git a/test/dummy/config/initializers/backtrace_silencers.rb b/spec/dummy/config/initializers/backtrace_silencers.rb similarity index 100% rename from test/dummy/config/initializers/backtrace_silencers.rb rename to spec/dummy/config/initializers/backtrace_silencers.rb diff --git a/test/dummy/config/initializers/inflections.rb b/spec/dummy/config/initializers/inflections.rb similarity index 100% rename from test/dummy/config/initializers/inflections.rb rename to spec/dummy/config/initializers/inflections.rb diff --git a/test/dummy/config/initializers/mime_types.rb b/spec/dummy/config/initializers/mime_types.rb similarity index 100% rename from test/dummy/config/initializers/mime_types.rb rename to spec/dummy/config/initializers/mime_types.rb diff --git a/test/dummy/config/initializers/secret_token.rb b/spec/dummy/config/initializers/secret_token.rb similarity index 100% rename from test/dummy/config/initializers/secret_token.rb rename to spec/dummy/config/initializers/secret_token.rb diff --git a/test/dummy/config/initializers/session_store.rb b/spec/dummy/config/initializers/session_store.rb similarity index 100% rename from test/dummy/config/initializers/session_store.rb rename to spec/dummy/config/initializers/session_store.rb diff --git a/test/dummy/config/initializers/wrap_parameters.rb b/spec/dummy/config/initializers/wrap_parameters.rb similarity index 100% rename from test/dummy/config/initializers/wrap_parameters.rb rename to spec/dummy/config/initializers/wrap_parameters.rb diff --git a/test/dummy/config/locales/en.yml b/spec/dummy/config/locales/en.yml similarity index 100% rename from test/dummy/config/locales/en.yml rename to spec/dummy/config/locales/en.yml diff --git a/test/dummy/config/routes.rb b/spec/dummy/config/routes.rb similarity index 100% rename from test/dummy/config/routes.rb rename to spec/dummy/config/routes.rb diff --git a/test/dummy/lib/assets/.gitkeep b/spec/dummy/lib/assets/.gitkeep similarity index 100% rename from test/dummy/lib/assets/.gitkeep rename to spec/dummy/lib/assets/.gitkeep diff --git a/test/dummy/log/.gitkeep b/spec/dummy/log/.gitkeep similarity index 100% rename from test/dummy/log/.gitkeep rename to spec/dummy/log/.gitkeep diff --git a/test/dummy/public/favicon.ico b/spec/dummy/log/test.log similarity index 100% rename from test/dummy/public/favicon.ico rename to spec/dummy/log/test.log diff --git a/test/dummy/public/404.html b/spec/dummy/public/404.html similarity index 100% rename from test/dummy/public/404.html rename to spec/dummy/public/404.html diff --git a/test/dummy/public/422.html b/spec/dummy/public/422.html similarity index 100% rename from test/dummy/public/422.html rename to spec/dummy/public/422.html diff --git a/test/dummy/public/500.html b/spec/dummy/public/500.html similarity index 100% rename from test/dummy/public/500.html rename to spec/dummy/public/500.html diff --git a/spec/dummy/public/favicon.ico b/spec/dummy/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/script/rails b/spec/dummy/script/rails similarity index 100% rename from test/dummy/script/rails rename to spec/dummy/script/rails diff --git a/spec/helpers/box_of_tricks_helper_spec.rb b/spec/helpers/box_of_tricks_helper_spec.rb new file mode 100644 index 0000000..b2c207c --- /dev/null +++ b/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 "
" + end + + it "should accept content as an argument" do + helper.field("hello").must_equal "
hello
" + end + + it "should accept content as a block" do + helper.field { "hello" }.must_equal "
hello
" + 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 "
hello
" + helper.field(id: "my_field", class: "other", data: {url: "/"}) { "hello" }. + must_be_dom_equal "
hello
" + end + + end + + describe :actions do + + it "should return a div with class 'actions'" do + helper.actions("").must_equal "
" + end + + it "should accept content as an argument" do + helper.actions("hello").must_equal "
hello
" + end + + it "should accept content as a block" do + helper.actions { "hello" }.must_equal "
hello
" + 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 "
hello
" + helper.actions(id: "my_field", class: "other", data: {url: "/"}) { "hello" }. + must_be_dom_equal "
hello
" + 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 %{} + end + + end + + describe :clearfix do + + it "it should add a br tag with class 'clear'" do + helper.clearfix.must_be_dom_equal %{
} + end + + end + + describe :div do + + it "should accept content as an argument" do + helper.div("bodacious").must_be_dom_equal %{
bodacious
} + end + + it "should accept content as a block" do + helper.div {"bodacious"}.must_be_dom_equal %{
bodacious
} + end + + it "should accept options for attributes" do + helper.div("hello", id: "my_field", class: "other"). + must_be_dom_equal "
hello
" + + helper.div(id: "my_field", class: "other") { "hello" }. + must_be_dom_equal "
hello
" + 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 %{
Bodacious
}, +# div_with_class(:user, "Bodacious") +# +# assert_dom_equal %{
Bodacious
}, +# div_with_class(:user, "Bodacious", class: "admin") +# +# assert_dom_equal %{
Bodacious
}, +# div_with_class(:user, "Bodacious", class: "admin", id: "user_1") +# +# assert_dom_equal %{
Bodacious
}, +# div_with_class(:user, class: "admin", id: "user_1") { "Bodacious" } +# end +# +# test "field" do +# assert_dom_equal %{

hello

}, +# field { content_tag(:p, "hello") } +# +# assert_dom_equal %{

hello

}, +# field(content_tag(:p, "hello")) +# end +# +# test "actions" do +# assert_dom_equal %{
hello
}, +# actions { "hello" } +# +# assert_dom_equal %{
hello
}, +# actions("hello") +# end +# +# test "div" do +# assert_dom_equal %{
hello
}, +# div("hello") +# +# assert_dom_equal %{
hello
}, +# div("hello", class: "spaniel", id: "hello_div", data: {url: "/"}) +# +# assert_dom_equal %{
Muppet 1
}, +# div(class: "muppet") { "Muppet 1" } +# end +# +# test "html5_shim" do +# assert_dom_equal %{}, +# html5_shim +# end +# +# test "clearfix" do +# assert_dom_equal %{
}, clearfix +# end +# +# end diff --git a/test/test_helper.rb b/spec/spec_helper.rb similarity index 91% rename from test/test_helper.rb rename to spec/spec_helper.rb index dcd3b27..5b55122 100644 --- a/test/test_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/support/dummy_view.rb b/spec/support/dummy_view.rb new file mode 100644 index 0000000..7b6663d --- /dev/null +++ b/spec/support/dummy_view.rb @@ -0,0 +1,5 @@ +class DummyView < ActionView::Base + + include BoxOfTricksHelper + +end \ No newline at end of file diff --git a/spec/support/helper_methods.rb b/spec/support/helper_methods.rb new file mode 100644 index 0000000..0cab173 --- /dev/null +++ b/spec/support/helper_methods.rb @@ -0,0 +1,3 @@ +def helper + @helper ||= DummyView.new +end diff --git a/spec/support/minitest/expectations.rb b/spec/support/minitest/expectations.rb new file mode 100644 index 0000000..9327c07 --- /dev/null +++ b/spec/support/minitest/expectations.rb @@ -0,0 +1,5 @@ +module MiniTest::Expectations + + infect_an_assertion :assert_dom_equal, :must_be_dom_equal, :reverse + +end \ No newline at end of file diff --git a/spec/support/minitest/matchers.rb b/spec/support/minitest/matchers.rb new file mode 100644 index 0000000..41ce5d7 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/test/unit/helpers/box_of_tricks_helper_test.rb b/test/unit/helpers/box_of_tricks_helper_test.rb deleted file mode 100644 index 320fa26..0000000 --- a/test/unit/helpers/box_of_tricks_helper_test.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'test_helper' - -class BoxOfTricksHelperTest < ActionView::TestCase - - test "title" do - title("Set Title") - assert_equal title, "Set Title" - end - - test "div_with_class" do - assert_dom_equal %{
Bodacious
}, - div_with_class(:user, "Bodacious") - - assert_dom_equal %{
Bodacious
}, - div_with_class(:user, "Bodacious", class: "admin") - - assert_dom_equal %{
Bodacious
}, - div_with_class(:user, "Bodacious", class: "admin", id: "user_1") - - assert_dom_equal %{
Bodacious
}, - div_with_class(:user, class: "admin", id: "user_1") { "Bodacious" } - end - - test "field" do - assert_dom_equal %{

hello

}, - field { content_tag(:p, "hello") } - - assert_dom_equal %{

hello

}, - field(content_tag(:p, "hello")) - end - - test "actions" do - assert_dom_equal %{
hello
}, - actions { "hello" } - - assert_dom_equal %{
hello
}, - actions("hello") - end - - test "div" do - assert_dom_equal %{
hello
}, - div("hello") - - assert_dom_equal %{
hello
}, - div("hello", class: "spaniel", id: "hello_div", data: {url: "/"}) - - assert_dom_equal %{
Muppet 1
}, - div(class: "muppet") { "Muppet 1" } - end - - test "html5_shim" do - assert_dom_equal %{}, - html5_shim - end - - test "clearfix" do - assert_dom_equal %{
}, clearfix - end - -end