Skip to content

Commit

Permalink
🤖👮 The project up.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed Aug 12, 2016
1 parent 7e101d5 commit 71fce65
Show file tree
Hide file tree
Showing 41 changed files with 118 additions and 225 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source 'https://rubygems.org'

gemspec

7 changes: 3 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ['lib','test']
t.test_files = Dir.glob("test/**/*_test.rb").sort
t.libs = %w(lib test)
t.test_files = Dir.glob('test/**/*_test.rb').sort
t.verbose = true
end

task :default => :test

task default: :test
14 changes: 5 additions & 9 deletions lib/minitest-spec-rails/dsl.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
module MiniTestSpecRails
module DSL

def self.included(klass)
klass.extend ClassMethods
remove_method :test if method_defined?(:test)
end

module ClassMethods

def describe(*args, &block)
stack = Minitest::Spec.describe_stack
stack.push self if stack.empty?
super(*args) { class_eval(&block) }
stack.pop if stack.length == 1
end

def before(type = nil, &block)
setup { self.instance_eval(&block) }
def before(_type = nil, &block)
setup { instance_eval(&block) }
end

def after(type = nil, &block)
teardown { self.instance_eval(&block) }
def after(_type = nil, &block)
teardown { instance_eval(&block) }
end

def test(name, &block)
it(name) { self.instance_eval(&block) }
it(name) { instance_eval(&block) }
end

def described_class
nil
end

end

def described_class
self.class.described_class
end

end
end
4 changes: 0 additions & 4 deletions lib/minitest-spec-rails/init/action_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module MiniTestSpecRails
module Init
module ActionControllerBehavior

extend ActiveSupport::Concern

included do
Expand All @@ -12,13 +11,10 @@ module ActionControllerBehavior
end

module Descriptions

def described_class
determine_default_controller_class(name)
end

end

end
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/minitest-spec-rails/init/action_dispatch.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
module MiniTestSpecRails
module Init
module ActionDispatchBehavior

extend ActiveSupport::Concern

included do
register_spec_type(/(Acceptance|Integration) ?Test\z/, self)
register_spec_type(self) { |desc| Class === desc && desc < self }
end

end
end
end
Expand Down
5 changes: 0 additions & 5 deletions lib/minitest-spec-rails/init/action_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module MiniTestSpecRails
module Init
module ActionMailerBehavior

extend ActiveSupport::Concern

included do
Expand All @@ -12,16 +11,12 @@ module ActionMailerBehavior
end

module Descriptions

def described_class
determine_default_mailer(name)
end

end

end
end
end

ActionMailer::TestCase.send :include, MiniTestSpecRails::Init::ActionMailerBehavior

4 changes: 0 additions & 4 deletions lib/minitest-spec-rails/init/action_view.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module MiniTestSpecRails
module Init
module ActionViewBehavior

extend ActiveSupport::Concern

included do
Expand All @@ -12,13 +11,10 @@ module ActionViewBehavior
end

module Descriptions

def described_class
determine_default_helper_class(name)
end

end

end
end
end
Expand Down
5 changes: 0 additions & 5 deletions lib/minitest-spec-rails/init/active_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module MiniTestSpecRails
module Init
module ActiveJobBehavior

extend ActiveSupport::Concern

included do
Expand All @@ -12,18 +11,14 @@ module ActiveJobBehavior
end

module Descriptions

def described_class
determine_constant_from_test_name(name) do |constant|
Class === constant && constant < ActiveJob::Base
end
end

end

end
end
end

ActiveJob::TestCase.send :include, MiniTestSpecRails::Init::ActiveJobBehavior

6 changes: 1 addition & 5 deletions lib/minitest-spec-rails/init/active_support.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module MiniTestSpecRails
module Init
module ActiveSupportBehavior

extend ActiveSupport::Concern

included do
Expand All @@ -13,20 +12,17 @@ module ActiveSupportBehavior
end

module Descriptions

def described_class
determine_constant_from_test_name(name) do |constant|
Class === constant
end
end

end

def initialize(*args)
Thread.current[:current_spec] = self
super
end if Minitest::VERSION < "5.3.3"

end if Minitest::VERSION < '5.3.3'
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions lib/minitest-spec-rails/init/mini_shoulda.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
module MiniTestSpecRails
module Init
module MiniShouldaBehavior

extend ActiveSupport::Concern

included do
class << self
alias :context :describe
alias :should :it
alias_method :context, :describe
alias_method :should, :it
end
extend ClassMethods
end

module ClassMethods

def should_eventually(desc)
it("should eventually #{desc}") { skip("Should eventually #{desc}") }
end

end

end
end
end
Expand Down
8 changes: 3 additions & 5 deletions lib/minitest-spec-rails/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module MiniTestSpecRails
class Railtie < ::Rails::Railtie

config.minitest_spec_rails = ActiveSupport::OrderedOptions.new
config.minitest_spec_rails.mini_shoulda = false

if ENV['RAILS_ENV'] == 'test'
config.before_initialize do |app|
config.before_initialize do |_app|
require 'active_support'
require 'minitest-spec-rails/init/active_support'
ActiveSupport.on_load(:action_controller) do
Expand All @@ -20,14 +19,13 @@ class Railtie < ::Rails::Railtie
end
end

initializer 'minitest-spec-rails.action_view', :after => 'action_view.setup_action_pack', :group => :all do |app|
initializer 'minitest-spec-rails.action_view', after: 'action_view.setup_action_pack', group: :all do |_app|
require 'minitest-spec-rails/init/action_view'
end

initializer 'minitest-spec-rails.mini_shoulda', :group => :all do |app|
initializer 'minitest-spec-rails.mini_shoulda', group: :all do |app|
require 'minitest-spec-rails/init/mini_shoulda' if app.config.minitest_spec_rails.mini_shoulda
end
end

end
end
2 changes: 1 addition & 1 deletion lib/minitest-spec-rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MiniTestSpecRails
VERSION = "5.4.0"
VERSION = '5.4.0'.freeze
end
4 changes: 2 additions & 2 deletions minitest-spec-rails.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "minitest-spec-rails/version"
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'minitest-spec-rails/version'

Gem::Specification.new do |gem|
gem.name = 'minitest-spec-rails'
Expand Down
16 changes: 7 additions & 9 deletions test/cases/action_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
class ModelsController < ApplicationController; end

class ActionControllerTest < MiniTestSpecRails::TestCase

it 'matches spec type for class constants' do
assert_controller MiniTest::Spec.spec_type(ApplicationController)
assert_controller MiniTest::Spec.spec_type(ModelsController)
end

it 'matches spec type for strings' do
assert_controller MiniTest::Spec.spec_type("WidgetController")
assert_controller MiniTest::Spec.spec_type("WidgetControllerTest")
assert_controller MiniTest::Spec.spec_type("Widget Controller Test")
assert_controller MiniTest::Spec.spec_type('WidgetController')
assert_controller MiniTest::Spec.spec_type('WidgetControllerTest')
assert_controller MiniTest::Spec.spec_type('Widget Controller Test')
# And is case sensitive
refute_controller MiniTest::Spec.spec_type("widgetcontroller")
refute_controller MiniTest::Spec.spec_type("widgetcontrollertest")
refute_controller MiniTest::Spec.spec_type("widget controller test")
refute_controller MiniTest::Spec.spec_type('widgetcontroller')
refute_controller MiniTest::Spec.spec_type('widgetcontrollertest')
refute_controller MiniTest::Spec.spec_type('widget controller test')
end

it 'wont match spec type for non space characters' do
refute_controller MiniTest::Spec.spec_type("Widget Controller\tTest")
refute_controller MiniTest::Spec.spec_type("Widget Controller\rTest")
refute_controller MiniTest::Spec.spec_type("Widget Controller\nTest")
refute_controller MiniTest::Spec.spec_type("Widget Controller\fTest")
refute_controller MiniTest::Spec.spec_type("Widget ControllerXTest")
refute_controller MiniTest::Spec.spec_type('Widget ControllerXTest')
end

private
Expand All @@ -36,5 +35,4 @@ def assert_controller(actual)
def refute_controller(actual)
refute_equal ActionController::TestCase, actual
end

end
22 changes: 10 additions & 12 deletions test/cases/action_dispatch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,36 @@
class ModelsController < ApplicationController; end

class ActionControllerTest < MiniTestSpecRails::TestCase

it 'resolves spec type for matching acceptance strings' do
assert_dispatch MiniTest::Spec.spec_type("WidgetAcceptanceTest")
assert_dispatch MiniTest::Spec.spec_type("Widget Acceptance Test")
assert_dispatch MiniTest::Spec.spec_type('WidgetAcceptanceTest')
assert_dispatch MiniTest::Spec.spec_type('Widget Acceptance Test')
# And is case sensitive
refute_dispatch MiniTest::Spec.spec_type("widgetacceptancetest")
refute_dispatch MiniTest::Spec.spec_type("widget acceptance test")
refute_dispatch MiniTest::Spec.spec_type('widgetacceptancetest')
refute_dispatch MiniTest::Spec.spec_type('widget acceptance test')
end

it 'wont match spec type for space characters in acceptance strings' do
refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\tTest")
refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\rTest")
refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\nTest")
refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\fTest")
refute_dispatch MiniTest::Spec.spec_type("Widget AcceptanceXTest")
refute_dispatch MiniTest::Spec.spec_type('Widget AcceptanceXTest')
end

it 'resolves spec type for matching integration strings' do
assert_dispatch MiniTest::Spec.spec_type("WidgetIntegrationTest")
assert_dispatch MiniTest::Spec.spec_type("Widget Integration Test")
assert_dispatch MiniTest::Spec.spec_type('WidgetIntegrationTest')
assert_dispatch MiniTest::Spec.spec_type('Widget Integration Test')
# And is case sensitive
refute_dispatch MiniTest::Spec.spec_type("widgetintegrationtest")
refute_dispatch MiniTest::Spec.spec_type("widget integration test")
refute_dispatch MiniTest::Spec.spec_type('widgetintegrationtest')
refute_dispatch MiniTest::Spec.spec_type('widget integration test')
end

it 'wont match spec type for space characters in integration strings' do
refute_dispatch MiniTest::Spec.spec_type("Widget Integration\tTest")
refute_dispatch MiniTest::Spec.spec_type("Widget Integration\rTest")
refute_dispatch MiniTest::Spec.spec_type("Widget Integration\nTest")
refute_dispatch MiniTest::Spec.spec_type("Widget Integration\fTest")
refute_dispatch MiniTest::Spec.spec_type("Widget IntegrationXTest")
refute_dispatch MiniTest::Spec.spec_type('Widget IntegrationXTest')
end

private
Expand All @@ -45,5 +44,4 @@ def assert_dispatch(actual)
def refute_dispatch(actual)
refute_equal ActionDispatch::IntegrationTest, actual
end

end
Loading

0 comments on commit 71fce65

Please sign in to comment.