Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Rails4 compatibility #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/minitest/rails/shoulda/matchers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "minitest/matchers"
require "minitest/rails"

if defined?(ActiveRecord)
if defined?(::ActiveRecord)
require "shoulda/matchers/active_record"

Shoulda::Matchers::ActiveRecord.module_eval do
Expand All @@ -12,7 +12,7 @@ def self.included(base)
end
end

class MiniTest::Rails::ActiveSupport::TestCase
class ActiveSupport::TestCase
include Shoulda::Matchers::ActiveRecord
end
end
Expand All @@ -28,7 +28,7 @@ def self.included(base)
end
end

class MiniTest::Rails::ActiveSupport::TestCase
class ActiveSupport::TestCase
include Shoulda::Matchers::ActiveModel
end
end
Expand All @@ -44,7 +44,8 @@ def self.included(base)
end
end

class MiniTest::Rails::ActionController::TestCase

class ActionController::TestCase
include Shoulda::Matchers::ActionController
end
end
Expand All @@ -60,7 +61,7 @@ def self.included(base)
end
end

class MiniTest::Rails::ActionMailer::TestCase
class ActionMailer::TestCase
include Shoulda::Matchers::ActionMailer
end
end
8 changes: 5 additions & 3 deletions minitest-rails-shoulda.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Gem::Specification.new do |s|
# s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_runtime_dependency "minitest-rails", "~> 0.5.0"
s.add_runtime_dependency "minitest-matchers", "~> 1.2.0"
s.add_runtime_dependency "shoulda-matchers", "~> 1.4.1"
s.add_runtime_dependency "minitest-rails", "~> 0.9.0"
s.add_runtime_dependency "minitest-matchers", "~> 1.3.0"
s.add_runtime_dependency "shoulda-matchers", "~> 2.0.0"
s.add_runtime_dependency "rails", "~> 4.0.0.beta1"

end
22 changes: 15 additions & 7 deletions test/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@ class TestApp < Rails::Application
end
class HelloController < ActionController::Base
def world
render inline: "<!DOCTYPE html><title>TestApp</title>
<h1>Hello <span>World</span></h1>
<nav><ul><li><a href='/'>home</a></li></ul></nav>
<p><label>Email Address<input type='text'></label></p>
<button>random button</button>
<label>going<input type='checkbox' checked='checked'></label>
<label>avoid<input type='checkbox'></label>"
respond_to do |format|
format.html do
render inline: "<!DOCTYPE html><title>TestApp</title>
<h1>Hello <span>World</span></h1>
<nav><ul><li><a href='/'>home</a></li></ul></nav>
<p><label>Email Address<input type='text'></label></p>
<button>random button</button>
<label>going<input type='checkbox' checked='checked'></label>
<label>avoid<input type='checkbox'></label>"
end
format.xml do
render inline: 'No!', status: :forbidden
end
end
end
end

Rails.application = TestApp

require 'rails/test_help'
require "minitest/rails"
require "minitest/rails/shoulda"

Expand Down
42 changes: 30 additions & 12 deletions test/test_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,63 @@

describe HelloController do

context "index" do
describe "index" do
setup do
get :world
end

describe "assertions" do
it "should give us HTML" do
assert_respond_with_content_type(@controller, :html)
get :world, format: :html
assert_respond_with(@controller, :success)
# @controller.should respond_with_content_type(:html)
# assert_respond_with_content_type(@controller, :html)
end

it "should not give us XML" do
refute_respond_with_content_type(@controller, :xml)
get :world, format: :xml
assert_respond_with(@controller, :forbidden)
# refute_respond_with_content_type(@controller, :xml)
end
end

describe "with matchers" do
should "give us HTML" do
@controller.must respond_with_content_type(:html)
it "should give us HTML" do
must respond_with(:success)
end

it "should eventually give us JSON" do
skip "should_eventually give us JSON"
end

should_eventually "give us JSON"

# should_eventually "give us JSON" do
# @controller.must respond_with_content_type(:json)
# end

should "not give us XML" do
@controller.wont respond_with_content_type(:xml)
it "should not give us XML" do
get :world, format: :xml
wont respond_with(:success)
end
end

describe "with subject" do
subject { @controller }

describe "Html request" do
it { must respond_with(:success) }
it { wont respond_with(:forbidden) }
end

describe "Forbidden XML request" do
before :each do
get :world, format: :xml
end
it { must respond_with(:forbidden) }
it { wont respond_with(:success) }
end

it { must respond_with_content_type(:html) }
it { wont respond_with_content_type(:xml) }

must { respond_with_content_type(:html) }
wont { respond_with_content_type(:xml) }
end
end

Expand Down