Skip to content

Instantly share code, notes, and snippets.

@ugisozols
Created December 12, 2011 13:19
Show Gist options
  • Save ugisozols/1467105 to your computer and use it in GitHub Desktop.
Save ugisozols/1467105 to your computer and use it in GitHub Desktop.
Refinery CMS specs using minitest
# Refinery CMS Core RSpec specs converted to MiniTest::Spec
# spec/minitest_helper.rb
require "minitest/spec"
require "minitest/autorun"
require "mocha"
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment", __FILE__)
Dir[File.expand_path("../../*/spec/support/**/*.rb", __FILE__)].each do |f|
require f
end
# core/spec/lib/refinery/core_spec.rb - minitest
require "minitest_helper"
describe Refinery do
# describe "#engines" do
# it "should return an array of modules representing registered engines" do
# subject.engines.should be_a(Array)
# subject.engines.each do |e|
# e.should be_a(Module)
# end
# end
# end
describe "#engines" do
it "should return an array of modules representing registered engines" do
Refinery.engines.must_be_kind_of Array
Refinery.engines.each do |e|
e.must_be_kind_of Module
end
end
end
# describe "#register_engine" do
# before(:each) { subject.engines.clear }
#
# it "should add the engine's module to the array of registered engines" do
# subject.register_engine(Refinery::Core)
#
# Refinery.engines.should include(Refinery::Core)
# Refinery.engines.should have(1).item
# end
#
# it "should not allow same engine to be registered twice" do
# subject.register_engine(Refinery::Core)
# subject.register_engine(Refinery::Core)
#
# Refinery.engines.should have(1).item
# end
# end
describe "#register_engine" do
before { Refinery.engines.clear }
it "should add the engine's module to the array of registered engines" do
Refinery.register_engine(Refinery::Core)
Refinery.engines.must_include Refinery::Core
Refinery.engines.size.must_equal 1
end
it "should not allow same engine to be registered twice" do
Refinery.register_engine(Refinery::Core)
Refinery.register_engine(Refinery::Core)
Refinery.engines.size.must_equal 1
end
end
# describe "#engine_registered?" do
# context "with Refinery::Core::Engine registered" do
# before(:each) { subject.register_engine(Refinery::Core) }
#
# it "should return true if the engine is registered" do
# subject.engine_registered?(Refinery::Core).should == true
# end
# end
#
# context "with no engines registered" do
# before(:each) { subject.engines.clear }
#
# it "should return false if the engine is not registered" do
# subject.engine_registered?(Refinery::Core).should == false
# end
# end
# end
describe "#engine_registered?" do
describe "with Refinery::Core::Engine registered" do
before { Refinery.register_engine(Refinery::Core) }
it "should return true if the engine is registered" do
Refinery.engine_registered?(Refinery::Core).must_equal true
end
end
describe "with no engines registered" do
before { Refinery.engines.clear }
it "should return false if the engine is not registered" do
Refinery.engine_registered?(Refinery::Core).must_equal false
end
end
end
# describe "#unregister_engine" do
# before(:each) do
# subject.engines.clear
# subject.register_engine(Refinery::Images)
# end
#
# it "should remove the engine's module from the array of registered engines" do
# subject.unregister_engine(Refinery::Images)
#
# subject.engines.should have(0).item
# end
# end
describe "#unregister_engine" do
before do
Refinery.engines.clear
Refinery.register_engine(Refinery::Images)
end
it "should remove the engine's module from the array of registered engines" do
Refinery.unregister_engine(Refinery::Images)
Refinery.engines.size.must_equal 0
end
end
# describe "#validate_engine!" do
# context "with a valid engine" do
# it "should return true" do
# subject.send(:validate_engine!, Refinery::ValidEngine)
# end
# end
#
# context "with an invalid engine" do
# it "should raise invalid engine exception" do
# lambda {
# subject.send(:validate_engine!, Refinery::InvalidEngine)
# }.should raise_error(Refinery::InvalidEngineError, "Engine must define a root accessor that returns a pathname to its root")
# end
# end
# end
describe "#validate_engine!" do
describe "with a valid engine" do
it "should return nil" do
Refinery.send(:validate_engine!, Refinery::ValidEngine).must_be_nil
end
end
describe "with an invalid engine" do
it "should raise invalid engine exception" do
lambda {
Refinery.send(:validate_engine!, Refinery::InvalidEngine)
}.must_raise(Refinery::InvalidEngineError)
end
end
end
# describe "#roots" do
# it "should return pathname to engine root when given constant as parameter" do
# subject.roots(Refinery::Core).should == Refinery::Core.root
# end
#
# it "should return pathname to engine root when given symbol as parameter" do
# subject.roots(:'refinery/core').should == Refinery::Core.root
# end
#
# it "should return pathname to engine root when given string as parameter" do
# subject.roots("refinery/core").should == Refinery::Core.root
# end
#
# it "should return an array of all pathnames if no engine_name is specified" do
# subject.roots.should be_a(Array)
# subject.roots.each do |root|
# root.should be_a(Pathname)
# end
# end
# end
describe "#roots" do
it "should return pathname to engine root when given constant as parameter" do
Refinery.roots(Refinery::Core).must_equal Refinery::Core.root
end
it "should return pathname to engine root when given symbol as parameter" do
Refinery.roots(:'refinery/core').must_equal Refinery::Core.root
end
it "should return pathname to engine root when given string as parameter" do
Refinery.roots("refinery/core").must_equal Refinery::Core.root
end
it "should return an array of all pathnames if no engine_name is specified" do
Refinery.roots.must_be_kind_of Array
Refinery.roots.each do |root|
root.must_be_kind_of Pathname
end
end
end
# describe "#deprecate" do
# before(:each) do
# @errors = StringIO.new
# @old_err = $stderr
# $stderr = @errors
# end
#
# after(:each) { $stderr = @old_err }
#
# it "shows a deprecation warning" do
# Refinery.deprecate("ugis")
# @errors.rewind
# @errors.read.should == "\n-- DEPRECATION WARNING --\nThe use of 'ugis' is deprecated.\n"
# end
#
# it "takes when option" do
# Refinery.deprecate("ugis", :when => "10.0")
# @errors.rewind
# @errors.read.should == "\n-- DEPRECATION WARNING --\nThe use of 'ugis' is deprecated and will be removed at version 10.0.\n"
# end
#
# it "takes replacement option" do
# Refinery.deprecate("ugis", :when => "10.0", :replacement => "philip")
# @errors.rewind
# @errors.read.should == "\n-- DEPRECATION WARNING --\nThe use of 'ugis' is deprecated and will be removed at version 10.0.\nPlease use philip instead.\n"
# end
# end
describe "#deprecate" do
it "shows a deprecation warning" do
lambda {
Refinery.deprecate("ugis")
}.must_output nil, "\n-- DEPRECATION WARNING --\nThe use of 'ugis' is deprecated.\n"
end
it "takes when option" do
lambda {
Refinery.deprecate("ugis", :when => "10.0")
}.must_output nil, "\n-- DEPRECATION WARNING --\nThe use of 'ugis' is deprecated and will be removed at version 10.0.\n"
end
it "takes replacement option" do
lambda {
Refinery.deprecate("ugis", :when => "10.0", :replacement => "philip")
}.must_output nil, "\n-- DEPRECATION WARNING --\nThe use of 'ugis' is deprecated and will be removed at version 10.0.\nPlease use philip instead.\n"
end
end
# describe "#i18n_enabled?" do
# it "returns true when Refinery::I18n.enabled? is true" do
# Refinery::I18n.stub(:enabled?).and_return(true)
# subject.i18n_enabled?.should == true
# end
#
# it "returns false when Refinery::I18n.enabled? is false" do
# Refinery::I18n.stub(:enabled?).and_return(false)
# subject.i18n_enabled?.should == false
# end
# end
describe "#i18n_enabled?" do
it "returns true when Refinery::I18n.enabled? is true" do
Refinery::I18n.stubs(:enabled?).returns(true)
Refinery.i18n_enabled?.must_equal true
end
it "returns false when Refinery::I18n.enabled? is false" do
Refinery::I18n.stubs(:enabled?).returns(false)
Refinery.i18n_enabled?.must_equal false
end
end
end
@parndt
Copy link

parndt commented Dec 12, 2011

What's the benefit (for us ) of minitest over rspec?

@ugisozols
Copy link
Author

  1. it's a bit faster than rspec
  2. the rails way

Other than that I don't have much to say. I started this just out of curiosity.

@ugisozols
Copy link
Author

Actually I'm not 100% sure about 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment