Coder Social home page Coder Social logo

metaskills / minitest-spec-rails Goto Github PK

View Code? Open in Web Editor NEW
395.0 9.0 53.0 326 KB

:bento: Make Rails Use MiniTest::Spec!

Home Page: http://github.com/metaskills/minitest-spec-rails

License: MIT License

Ruby 99.80% HTML 0.19% JavaScript 0.01%

minitest-spec-rails's Introduction

Make Rails Use Minitest::Spec!

The minitest-spec-rails gem makes it easy to use the Minitest::Spec DSL within your existing Rails 2.3, 3.x or 4.x test suite. It does this by forcing ActiveSupport::TestCase to utilize the Minitest::Spec::DSL.

Gem Version CI Status Maintainability

Usage

Existing or new Rails applications that use the default Rails testing structure can simply drop in the minitest-spec-gem and start writing their tests in the new spec DSL. Since Minitest::Spec is built on top of Minitest::Unit, a replacement for Test::Unit, all of your existing tests will continue to work.

Rails 4.1 to 6.0

Our master branch is tracking rails 5.1 up to 6.x active development.

group :test do
  gem 'minitest-spec-rails'
end

For Rails 3.x or 4.0

Our 3-x-stable branch is meant for both Rails 3.x or 4.0 specifically. This version uses the latest 4.x series of minitest.

group :test do
  gem 'minitest-spec-rails', '~> 4.7'
end

How is this different than Minitest::Rails?

To start off both Mike Moore (@blowmage) and I have worked together and we both LOVE Minitest::Spec. Both projects aim to advocate Minitest and make Rails integration as easy as possible. However, there are a few key differences in our projects. Some of these differences may go away in time too. As always, choose the tool you think fits your needs. So how, is minitest-spec-rails different than minitest-rails?

  • We aim to leverage existing Rails test directories and files!
  • No special test helper and/or generators.
  • Easy migration path for existing Rails applications.
  • How we go about freedom patching Rails.
  • Fully support Ruby 1.8.7 with all legacy Test::Unit behavior.
  • Compatibility with ActiveSupport::TestCase's setup and teardowns.

So the goal of this project is to make Rails 3 or 4 applications just work as if rails-core had decided to support Minitest::Spec all along. We believe that eventually that day will come and when it does, all your tests will still work! So bundle up and get started!

gem 'minitest-spec-rails'

Test Styles

This cheat sheet shows both the Minitest::Unit assertions along with the Minitest::Spec assertion syntax. Remember, Minitest::Spec is built on top of Minitest::Unit which is a Test::Unit replacement. That means you can mix and match styles as you upgrade from Test::Unit to a more modern style. For example, both of these would work in Minitest::Spec and are interchangeable.

# Minitest::Unit Assertion Style:
assert_equal 100, foo

# Minitest::Spec Assertion Style:
expect(foo).must_equal 100
require 'test_helper'
class UserTest < ActiveSupport::TestCase
  let(:user_ken)   { User.create! :email => '[email protected]' }
  it 'works' do
    expect(user_ken).must_be_instance_of User
  end
end
require 'test_helper'
describe User do
  # THIS IS NOT RECOMMENDED!
end

RSpec 3 is also moving away from the outer describe test type inference, as described in this line from their release notes.

Spec types are no longer inferred by location, they instead need to be explicitly tagged. The old behaviour is enabled by config.infer_spec_type_from_file_location!, which is still supplied in the default generated spec_helper.rb. (Xavier Shay, Myron Marston)

Not that we want to mimic RSpec, but the aim of this gem is very straight forward and minimalistic. We simply want to expose the Minitest Spec::DSL and core assertion style within ActiveSupport. Period. So it is very possible that us matching outer describe to classes is simply going to go away one day soon.

Just for reference, here is a full list of each of Rails test case we support.

# Model Test (or anything else not listed below)
class UserTest < ActiveSupport::TestCase
end

# Controller Test
class UsersControllerTest < ActionController::TestCase
end

# Integration Tests - Must use subclass style!
class IntegrationTest < ActionDispatch::IntegrationTest
end

# Mailer Test
class UserMailerTest < ActionMailer::TestCase
end

# View Helper Test
class UsersHelperTest < ActionView::TestCase
end

# Job Helper Test
class MyJobTest < ActiveJob::TestCase
end

Extras

We have baked in a few extra methods behind the scenes to minitest-spec-rails. Most directly support our needs to reflect on described classes, however, they may be useful to you too when meta-programming on top of minitest-spec-rails.

#described_class

The described_class method is available both via a class method and an instance method in any Rails test case. It is guaranteed to work despite the described level too. This allows class level macros to be built, much like Shoulda. Remember, it can only do this if you follow Rails naming conventions for your tests.

class UserTest < ActiveSupport::TestCase
  described_class # => User(id: integer, email: string)
  it 'works here' do
    described_class # => User(id: integer, email: string)
  end
  describe 'and' do
    it 'works here too' do
      described_class # => User(id: integer, email: string)
    end
  end
end

Setup & Teardown Compatability

Rails ActiveSupport::TestCase allows multiple setup and teardown methods per class. It also allows you to specify these either with a symbol or a block. Unlike normal ActiveSupport setup and teardown callbacks, our blocks are evaluated in the scope of the instance, just like before and after. So this just works!

class ActiveSupportCallbackTest < ActiveSupport::TestCase

  setup :foo
  setup :bar
  before { @bat = 'biz' }

  it 'works' do
    expect(@foo).must_equal 'foo'
    expect(@bar).must_equal 'bar'
    expect(@bat).must_equal 'biz'
  end

  private

  def foo ; @foo = 'foo' ; end
  def bar ; @bar = 'bar' ; end

end

mini_shoulda

If you are migrating away from Shoulda, then minitest-spec-rails' mini_shoulda feature will help. To enable it, set the following configuration in your test environment file.

# In config/environments/test.rb
config.minitest_spec_rails.mini_shoulda = true

Doing so only enables a few aliases that allow the Shoulda context, should, and should_eventually methods. The following code demonstrates the full features of the mini_shoulda implementation. It basically replaces the shell of shoulda-context in a few lines of code.

class PostTests < ActiveSupport::TestCase
  setup    { @post = Post.create! :title => 'Test Title', :body => 'Test body' }
  teardown { Post.delete_all }
  should 'work' do
    @post.must_be_instance_of Post
  end
  context 'with a user' do
    should_eventually 'have a user' do
      # ...
    end
  end
end

If you prefer the assertions provided by shoulda-context like assert_same_elements, then you may want to consider copying them from here and including them in Minitest::Spec yourself. I personally recommend just replacing these assertions with something more modern. A few examples are below.

assert_same_elements a, b         # From
expect(a.sort).must_equal b.sort  # To

assert_does_not_contain a, b  # From
expect(a).wont_include b      # To

Matchers

I highly suggest that you stay away from matchers since Minitest::Spec gives you all the tools you need to write good tests. Staying away from matchers will make your code's tests live longer. So my advice is to stay away from things like .should == and just write .must_equal instead. However, if matchers are really your thing, I recommend the minitest-matchers gem. You can also check out the valid_attribute gem built on top of minitest-matchers.

describe Post do
  subject { Post.new }
  it { must have_valid(:title).when("Hello") }
  it { wont have_valid(:title).when("", nil, "Bad") }
end

Alternatively, try the mintest-matchers_vaccine gem to avoid infecting the objects that you want to test.

describe User do
  subject { User.new }
  it "should validate email" do
    must have_valid(:email).when("[email protected]", "[email protected]")
    wont have_valid(:email).when(nil, "", "foo", "foo@bar")
  end
end

Gotchas

Assertion Methods

If you are upgrading from Test::Unit, there are a few missing assertions that have been renamed or are no longer available within Minitest.

  • The method assert_raise is renamed assert_raises.
  • There is no method assert_nothing_raised. There are good reasons for this on Ryan's blog entry.

Mocha

If you are using Mocha for mocking and stubbing, please update to the latest, 0.13.1 or higher so it is compatible with the latest Minitest. If you do not like the deprecation warnings in older versions of Rails, just add this below the require 'rails/all' within your application.rb file :)

require 'mocha/deprecation'
Mocha::Deprecation.mode = :disabled

Rails 3.0.x

If you are using minitest-spec-rails with Rails 3.0, then your controller and mailer tests will need to use the tests interface for the assertions to be setup correctly within sub describe blocks. I think this is a bug with class_attribute within Rails 3.0 only. So use the following patterns.

class UsersControllerTest < ActionController::TestCase
  tests UsersController
end
class UserMailerTest < ActionMailer::TestCase
  tests UserMailer
end

Rails 3.1 & 3.2

If your view helper tests give you an eror like this: RuntimeError: In order to use #url_for, you must include routing helpers explicitly., this is something that is broken only for Rails 3.1 and 3.2, both 3.0 and 4.0 and above do not exhibit this error. I have heard that if you include Rails.application.routes.url_helpers in your tests or inject them into the helper module before the test it may work. Lemme know what you find out.

Contributing

We run our tests on GitHub Actions. If you detect a problem, open up a github issue or fork the repo and help out. After you fork or clone the repository, the following commands will get you up and running on the test suite.

$ bundle install
$ bundle exec appraisal update
$ bundle exec appraisal rake test

We use the appraisal gem from Thoughtbot to help us generate the individual gemfiles for each Rails version and to run the tests locally against each generated Gemfile. The rake appraisal test command actually runs our test suite against all Rails versions in our Appraisal file. If you want to run the tests for a specific Rails version, use bundle exec appraisal -h for a list. For example, the following command will run the tests for Rails 4.1 only.

$ bundle exec appraisal rails_v6.0.x rake test
$ bundle exec appraisal rails_v6.1.x rake test
$ bundle exec appraisal rails_v7.0.x rake test

We have a few branches for each major Rails version.

  • 2-3-stable - Tracks Rails 2.3.x with MiniTest 4.x.
  • 3-x-stable - Oddly tracks Rails 3.x and 4.0 with MiniTest 4.x.
  • master - Currently tracks Rails 4.1 which uses Minitest 5.0.

minitest-spec-rails's People

Contributors

billturner avatar bingram-eab avatar chmurph2 avatar cmar avatar danmcclain avatar evgeni avatar ezkl avatar hal-henningsmoen avatar jaredbeck avatar jlsherrill avatar joelparkerhenderson avatar kamui avatar kimsuelim avatar marcoroth avatar metaskills avatar orangejulius avatar padi avatar qqwy avatar rmm5t avatar seuros avatar shime avatar tijn avatar woller avatar zofrex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minitest-spec-rails's Issues

Using test instead of it results in tests being added to previous describes.

I noticed with a failing assertion that tests declared with "test" instead of "it" following a describe are added to all the previous describes. For example:

describe Post do
  describe "create" do
    test "must do something" do
       assert true
    end
  end

  test "delete" do
    flunk
  end

  it "must fail" do
    assert false
  end
end

When I run this test, I get a single failure (Post::must fail) but 2 flunks (Post::delete and Post::create::delete).

I assume I shouldn't use the "test" method and use "it" instead, but shouldn't minitest-spec-rails overwrite the "test" method as an alias of "it"?

The following snippet fixes the problem somehow, but the reporters then place numbers in test descriptions:

module Minitest::Spec::DSL
  def test desc = "anonymous", &block
    it desc, &block
  end
end

ActiveSupport::TestCase used when testing module

Hi,

I'm using minitetest-spec-rails and I have a test case that tests some functionality on a module (some module methods). The gem registers ActiveSupport::TestCase as the base class for all class tests:

register_spec_type(self) { |desc| Class === desc }

For my use-case I would need this to be registered as the spec type for modules as well. Now it just uses the default Minitest::Spec. I fixed this by adding this to my test_helper.rb but I think you may want this to be default behavior.

MiniTest::Spec.register_spec_type(ActiveSupport::TestCase) { |desc| Module === desc }

Kind regards,

Stefan

View helper tests setting up controller incorrectly

I'm migrating my application to minitest-spec from TestUnit/shoulda and have run into an odd issue. Basically all of my helper specs are encountering an error on the first test to get run. A minimal test case to replicate the issue is outlined in this gist. I ran the minimal test case in the traditional TestUnit style with and without minitest-spec-rails both of which worked just fine but when I switch to the describe syntax I encounter the problem.

uses safe_constantize which was added in Rails 3.2

I just upgraded to v3.0.5 from v3.0.1 of this gem and my app is still using Rails 3.1. I'm now seeing an error saying

NoMethodError: undefined method `safe_constantize'

safe_constantize was introduced in Rails 3.2 so the gemspec is incorrect now. The gemspec says this gem works in ~ 3.0.

I'd love to see an update to get it to work per the gemspec but for now I'm downgrading back to 3.0.1

(e)

How to write routing tests?

I'm having some trouble running routing tests and I'm not sure if I'm doing it wrong or it's a problem with the minitest-spec-rails gem. This is my test:

require "test_helper"

class HomepageRouteTest < ActionDispatch::IntegrationTest
  def test_homepage
    assert_routing "/", :controller => "home", :action => "index"
  end
end

but the error I'm getting is:

  1) Error:
HomepageRouteTest#test_homepage:
NoMethodError: undefined method `recognize_path' for nil:NilClass
    /Users/jasperkennis/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/testing/assertions/routing.rb:210:in `recognized_request_for'
    /Users/jasperkennis/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/testing/assertions/routing.rb:42:in `assert_recognizes'
    /Users/jasperkennis/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/testing/assertions/routing.rb:118:in `assert_routing'
    test/routes/homepage_test.rb:5:in `test_homepage'

and to be complete, this is my test helper file:

ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)

Ignores `use_transactional_fixtures` setting

MTSR 5.1.1 fails to run ActiveRecord::TestFixtures#setup_fixtures, causing the use_transactional_fixtures setting to be ignored.

Without describe, setup_fixtures is called:

class BananaTest < ActiveSupport::TestCase
  # ..
end

With describe, setup_fixtures is not called:

describe Banana do
  # ..
end

I'd like to use describe.

Reproducible in MTSR 5.0.4 and 5.1.1.

Unable to use routing helpers in helper test with Rails 4.0

I know the readme says that this is a known bug in Rails 3.1 and 3.2, but I'm on 4.0.3 and seem to be experiencing it. I've got a very simple helper that uses a route helper. When I try to write a helper test that exercises that helper, I get this (sanitized):

RuntimeError: In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers
    /Users/brandon/Code/canary/vendor/ruby/2.0.0/gems/actionpack-4.0.3/lib/abstract_controller/url_for.rb:13:in `_routes'
    /Users/brandon/Code/canary/vendor/ruby/2.0.0/gems/actionpack-4.0.3/lib/action_view/test_case.rb:259:in `method_missing'

My understanding is I shouldn't have to include the routing helpers for helpers testsโ€”they should just work. However, if I do include the routing helpers in the helper with include Rails.application.routes.url_helpers, I get a different error:

RuntimeError: In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers
    /Users/brandon/Code/canary/vendor/ruby/2.0.0/gems/actionpack-4.0.3/lib/abstract_controller/url_for.rb:13:in `_routes'
    /Users/brandon/Code/canary/vendor/ruby/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/routing/url_for.rb:167:in `optimize_routes_generation?'
    /Users/brandon/Code/canary/vendor/ruby/2.0.0/gems/actionpack-4.0.3/lib/action_view/routing_url_for.rb:103:in `optimize_routes_generation?'
    /Users/brandon/Code/canary/vendor/ruby/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:204:in `optimize_routes_generation?'
    /Users/brandon/Code/canary/vendor/ruby/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:172:in `call'
    /Users/brandon/Code/canary/vendor/ruby/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:274:in `block (2 levels) in define_url_helper'

Is there something I'm missing or is this a bug in Rails and/or minitest-spec-rails?

Failing on latest rails 4.1 master

lib/minitest-spec-rails/init/action_view.rb:9:in block in <module:ActionViewBehavior>': undefined methodregister_spec_type' for ActionView::TestCase:Class (NoMethodError)

Using minitest-spec-rails at 875c747 and rails at 75bb2bbebb95a05bbe2828dec7b678d31e2ebc80

Assertions running on nil object when using Describe Syntax on Models

I'm using the most recent versions Rails, Minitest and Minitest-spec-rails and I'm running into some problems with assertions.

Here's my spec:

require 'minitest/autorun'

ENV["RAILS_ENV"] = "test"
require File.expand_path('../../../config/environment', __FILE__)
require 'rails/test_help'

describe User do
  subject { User.new }
  it "must validate length of username" do
    "foo".must_equal "foo"
  end
end

When I run the test, i get this error:


  1) Error:
User#test_0001_must validate length of username:
NoMethodError: undefined method `assert_equal' for nil:NilClass
    (eval):8:in `must_equal'
    /Users/dc/dev/ruby/railsapp/spec/models/user_spec.rb:11:in `block (2 levels) in <top (required)>'

When i change describe User do to describe "User" do, the test executes correctly.

Here's my Gemfile, so you can see my dependencies.

source 'https://rubygems.org'

gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'doorkeeper', '~> 0.7.0'
gem 'devise', '~> 3.2.0'
gem 'pg', '~> 0.17.0'

gem 'resque', "~> 2.0.0.pre.1", github: "resque/resque"
gem 'resque_mailer', '~> 2.2.6'
gem 'devise-async', '~>  0.9.0'

group :development, :test do
  gem 'pry', '~> 0.9'  
end

group :test do
  gem 'minitest', '~> 5.0.8'
  gem 'minitest-focus'
  gem 'minitest-reporters', '~> 1.0.0.beta3'
  gem 'minitest-spec-rails', github: 'metaskills/minitest-spec-rails'
end

how to test helpers with minitest?

Hello,

This is not a bug in the gem but rather a question as how one should go about testing helper functions that are used in the view?

For instance, if I have a test/test_helper.rb file like so:

## MiniTest Setup!
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'minitest/autorun'
require 'capybara/rails'
require 'minitest/wscolor'
require 'capybara/poltergeist'


## Use rack_test as default driver
Capybara.default_driver = :rack_test

## Use poltergeist js driver
Capybara.javascript_driver = :poltergeist


## View tests  
class ViewTest < Minitest::Spec
  include Rails.application.routes.url_helpers
  include Capybara::DSL

  register_spec_type /view$/, self
end

What must I edit in order to access the helper methods in a helper file .. say helpers/info_pages_helper.rb

I want to be able to directly test those helper methods in minitest.. any help would be greatly appreciated

Rails 4.2.0.beta1 Compat

This is going to be bit of a hit-and-run, sorry! But in case anyone else is running into the same thing โ€ฆ

If you try minitest-spec-rails with Rails 4.2.0.beta1 (after bumping deps) bin/rake fails with:

rake aborted!
NameError: method `describe' not defined in Class
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/minitest-spec-rails-3902126c3c11/lib/minitest-spec-rails/init/active_support.rb:8:in `remove_method'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/minitest-spec-rails-3902126c3c11/lib/minitest-spec-rails/init/active_support.rb:8:in `block (2 levels) in <module:ActiveSupportBehavior>'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/minitest-spec-rails-3902126c3c11/lib/minitest-spec-rails/init/active_support.rb:8:in `class_eval'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/minitest-spec-rails-3902126c3c11/lib/minitest-spec-rails/init/active_support.rb:8:in `block in <module:ActiveSupportBehavior>'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta1/lib/active_support/concern.rb:120:in `class_eval'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta1/lib/active_support/concern.rb:120:in `append_features'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/minitest-spec-rails-3902126c3c11/lib/minitest-spec-rails/init/active_support.rb:19:in `include'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/minitest-spec-rails-3902126c3c11/lib/minitest-spec-rails/init/active_support.rb:19:in `<top (required)>'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta1/lib/active_support/dependencies.rb:248:in `require'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta1/lib/active_support/dependencies.rb:248:in `block in require'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta1/lib/active_support/dependencies.rb:233:in `load_dependency'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta1/lib/active_support/dependencies.rb:248:in `require'
/Users/ehayes/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/minitest-spec-rails-3902126c3c11/lib/minitest-spec-rails.rb:10:in `<top (required)>'
...

So it looks like the describe method isn't there to remove anymore. However, skipping the removal seemed to work for me.

I forked the gem here: https://github.com/hayesr/minitest-spec-rails

I bumped the version in the master branch to make it installable with Rails 4.2.0.beta1. You can use it to see the error.

I made a rails42 branch and removed the line 8 of init/active_support.

TBH, I didn't understand the Appraisal thing, it appears to be commented out. I ran rake test alone and that passed.

My rails42 branch worked in my project.

NoMethodError: undefined method `describe'

bundle install
...
Using sass-rails 5.0.4
Using rails 4.2.6
Using web-console 2.3.0
Using jquery-datatables-rails 3.4.0
Using minitest-spec-rails 5.3.0

rake test test/controllers/gig_confirmation_controller_test.rb
NoMethodError: undefined method `describe'
require 'test_helper'
class GigConfirmationsControllerTest < ActionController::TestCase
describe :create do
    let(:data) do
      {
        gig_confirmation: {
          gig_id: gig.id,
          confirmer_email: '[email protected]',
          confirmer_first_name: 'Some Text',
          confirmer_last_name: 'Some Text',
          confirmer_role: 'Role',
          message: false
        }
      }
    end
    let(:gig) do
      @gig1_post1_profile1_admin
    end

    describe 'not logged in' do
      it 'should redirect to login' do
        post :create, data
        assert_redirected_to :login
        assert_equal 'Please login.', flash[:danger]
      end
    end
end
end

Can you bump to minitest 3?

Minitest 3 is ready. Can you bump the dependency? Thanks, Joel

Fetching gem metadata from https://rubygems.org/.......
Bundler could not find compatible versions for gem "minitest":
In Gemfile:
minitest-spec-rails (>= 0) ruby depends on
minitest (~> 2.11) ruby

minitest (3.0.0)

No subclass name for inner describes

The subclass name is correctly displayed for tests that are direct, but skipped for tests that are within an inner describe. I don't have the problem when using an outer describe, but I'd like to follow your advice of using the subclass convention.

I've got the issue with all reporters (default minitest, turn, minitest-reporters and minitest-colorize) in a rails 4 app.

For example:

class SomeTest < ActiveSupport::TestCase
  test "thing" do
      flunk
  end

  describe "inner describe" do
    test "thing" do
      flunk
    end
  end
end

Reporters will display something like:

FAIL SomeTest#test_thing
FAIL inner describe#test_thing

Where it should display:

FAIL SomeTest#test_thing
FAIL SomeTest::inner describe#test_thing

I'm running:

  • rails 4.0.0.beta1
  • minitest 4.7.0
  • minitest-spec-rails 4.7.2

Sample minitest_helper file?

Since this is a "drop in replacement," what does a sample minitest_helper file look like for this gem? Also, how do we use it with capybara?

How to include FactoryGirl?

I've attempted to extend MiniTest to include the factory girl methods with little luck. Including in test_helper.rb:

# MiniTest
class MiniTest::Unit::TestCase
  include FactoryGirl::Syntax::Methods
end

# MiniTest::Spec
class MiniTest::Spec
  include FactoryGirl::Syntax::Methods
end

Doesn't allow for direct access to FactoryGirl methods, and not really sure what else to try? Any help would be greatly appreciated.

minitest-rails and minitest-spec-rails

Can we drop this gem in favor of minitest-rails. It's more popular and provides the functionality necessary for integrating minitest with rails. We could work together on one project instead of competing.

Expected to work with Rails engines?

It may be this is simply not expected to work with Rails engines?

I have a Rails engine skeleton created with rails plugin new --full. This also creates a dummy Rails app for use under testing. The engine was created with and uses Rails 4.1. I include minitest-spec-rails in the Gemfile (and/or gemspec). (Is there any other setup other than this?)

But undefined methoddescribe' for main:Object (NoMethodError)`

Am I doing something wrong, or is minitest-spec-rails just not meant for Rails engines?

MiniTest Extension Support

I may just doing something wrong but I've tried two MiniTest extensions, and both give me an undefined method 'foobar' for #<Class:0xDEADBEEF>.

I believe the error is raised because MiniTest::Spec is modified by the extensions instead of MiniTest::Spec::DSL, which is what lib/minitest-spec-rails/init/active_support.rb pulls into ActiveSupport::TestCase.

I'm not experienced enough to understand why the DSL is in a module under the class, or why the extensions don't tamper with that instead. Is this something that can be accounted for in this gem? Should I be creating issues on the other extensions instead?

For reference, I am on Ruby 2.0.0, Rails 4. The extensions I was trying to use:
https://github.com/ywen/minitest-spec-context
https://github.com/splattael/minitest-around

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can image, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post aobut this project for more information.

Cannot use with database_cleaner gem

I am trying to use your gem with database_cleaner. In my testhelper.rb I have the following:

require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
MiniTest::TestCase.add_setup_hook { DatabaseCleaner.start }
MiniTest::TestCase.add_teardown_hook { DatabaseCleaner.clean }

The hooks are necessary as if you use before and after like they do here:
https://github.com/bmabey/database_cleaner
you will override them when you use before and after blocks in your test.

I keep getting this message though:

rake aborted!
NameError: uninitialized constant Minitest::TestCase
/home/lee/Code/mobifit/test/test_helper.rb:47:in `<top (required)>'
/home/lee/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/test_unit/sub_test_task.rb:114:in `block (3 levels) in define'
/home/lee/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/test_unit/sub_test_task.rb:114:in `each'
/home/lee/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/test_unit/sub_test_task.rb:114:in `block (2 levels) in define'
/home/lee/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/test_unit/sub_test_task.rb:113:in `each'
/home/lee/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/test_unit/sub_test_task.rb:113:in `block in define'
/home/lee/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/test_unit/sub_test_task.rb:31:in `create_and_run_single_test'
/home/lee/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/test_unit/sub_test_task.rb:17:in `invoke_rake_task'
/home/lee/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0.rc2/lib/rails/test_unit/testing.rake:8:in `block in <top (required)>'
-e:1:in `<main>'
Tasks: TOP => test:single
(See full trace by running task with --trace)

Googling yields nothing, so I don't know where the problem lies.

before/setup inconsistency

I noticed an inconsistency between setup method and before blocks. I always considered them to be equivalent but here is what happens:

This gem defines the before method here.
The setup method called is this one which according to the comment:
# Add a callback, which runs before <tt>TestCase#setup</tt>.
will call the code in the before block before TestCase#setup.

This creates the following problem (real scenario follows)
I define setup in my test_helper file and I run DatabaseCleaner.start in there. This is supposed to run before any fixtures are added in the database. I create fixtures with FactoryGirl inside before blocks in tests. Those fixtures won't get cleaned because they where created before my setup method gets to run
(end of real scenario)

The actual problem is that if I call before do instead of def setup in my test_helper.rb file then the order is reversed. The code in helper's before runs first then the code in test's before block (and the real scenario bug is gone). I think many people consider setup and before to be equivalent and I've seen the same "bug" in other projects going unnoticed. If this is by design then I think is should be better documented.

I created a demo app to demonstrate the problem here. Simply pull the repo and call bin/rake test test/models/dummy_model_test.rb and see the problem live.

P.S.
There is an other implementation of before in minitest/spec which seems to be doing it correctly. Not sure if this is the one overriden though.

let is not limited to context block

I am not sure if there is a reason for this, but when I have a let state in a context block. I am coming from the RSpec world and have done this in the past with RSpec. If this isn't a recommended practice I understand. I have an example below, to better explain.

  class UserControllerTest < ActionController::TestCase
    describe '#create' do
       context 'with valid attributes' do
         let(:action) { post :create, user: {name: 'Ryan'} }

         #valid attribute tests go here
       end
       context 'with valid attributes' do
         let(:action) { post :create, user: {name: 'Ted'} } #overwrites the first let statement in this block since they have the same name

         #invalid attribute tests go here
       end
    end
  end

described_class references the TestCase class in some scenarios

When a describe block is labeled with a :: prefix to denote class methods, described_class resolves the wrong constant. Instead of the subject class, it gets the test class itself.

require 'minitest/autorun'
require 'test_helper'
require 'json_web_token'

class JsonWebTokenTest < ActiveSupport::TestCase
  describe '::encode' do
    let(:claims) { {'user_id' => 555} }

    it 'encodes a hash of claims to a URL safe string' do
      described_class.encode(claims)
      # => NoMethodError: undefined method `encode' for JsonWebTokenTest:Class
    end
  end
end

Changing describe '::encode' to `describe '.encode' fixes it.

Issues integrating with Guard-Minitest + Spork-minitest

I love this gem but am having difficulty integrating spork ... and guard for automated testing.

I think its related to drb...

In the guard file.. I am recommended to use:

guard 'minitest', :drb => true do
  # ...
end

but it fails with that, giving a drb connection refused error.. so only this method works:

guard 'minitest', :drb => false do
  # ...
end

Any ideas how I can get the drb setting to work? Without the drb setting, am I missing out on performance a lot?

Can't use nested describe blocks in controller tests

Here are the steps to reproduce. Create a new rails app:

$ rails new mts_test
$ cd mts_test/
$ echo "gem 'minitest-spec-rails'" >> Gemfile
$ bundle
$ rails g scaffold widget name:string
$ rake db:migrate

Now update the test/functional/widgets_controller_test.rb test to the following:

require 'test_helper'

describe WidgetsController do
  describe "index" do
    it "succeeds" do
      get :index
      assert_response :success
      refute_nil assigns(:widgets)
    end
  end
end

Then run your tests. The "NameError: wrong constant name index" error is from the nested describe. Try changing the describe clock's string to "index action" and you will get the error "NameError: wrong constant name index action".

$ rake
Rack::File headers parameter replaces cache_control after Rack 1.5.
Run options: --seed 41875

# Running tests:



Finished tests in 0.002314s, 0.0000 tests/s, 0.0000 assertions/s.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
Rack::File headers parameter replaces cache_control after Rack 1.5.
Run options: --seed 24962

# Running tests:

E

Finished tests in 0.038663s, 25.8645 tests/s, 0.0000 assertions/s.

  1) Error:
test_0001_succeeds(WidgetsController::index):
NameError: wrong constant name index
    *GEMPATH*/activesupport-3.2.11/lib/active_support/inflector/methods.rb:230:in `const_defined?'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/inflector/methods.rb:230:in `block in constantize'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/inflector/methods.rb:229:in `each'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/inflector/methods.rb:229:in `constantize'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/inflector/methods.rb:260:in `safe_constantize'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/core_ext/string/inflections.rb:66:in `safe_constantize'
    *GEMPATH*/actionpack-3.2.11/lib/action_controller/test_case.rb:379:in `determine_default_controller_class'
    *GEMPATH*/actionpack-3.2.11/lib/action_controller/test_case.rb:374:in `controller_class'
    *GEMPATH*/actionpack-3.2.11/lib/action_controller/test_case.rb:483:in `setup_controller_request_and_response'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/callbacks.rb:418:in `_run__2957963386970996437__setup__952493641747501755__callbacks'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/testing/setup_and_teardown.rb:35:in `run'

  2) Error:
test_0001_succeeds(WidgetsController::index):
NoMethodError: undefined method `each' for nil:NilClass
    *GEMPATH*/activerecord-3.2.11/lib/active_record/fixtures.rb:878:in `teardown_fixtures'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `_run__2957963386970996437__teardown__952493641747501755__callbacks'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_teardown_callbacks'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
    *GEMPATH*/activesupport-3.2.11/lib/active_support/testing/setup_and_teardown.rb:44:in `run'

1 tests, 0 assertions, 0 failures, 2 errors, 0 skips
Errors running test:functionals! #<RuntimeError: Command failed with status (1): [ruby -I"lib:test" -I"*GEMPATH*/rake-10.0.3/lib" "*GEMPATH*/rake-10.0.3/lib/rake/rake_test_loader.rb" "test/functional/**/*_test.rb" ]>
Run options: --seed 65435

# Running tests:



Finished tests in 0.001056s, 0.0000 tests/s, 0.0000 assertions/s.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

FWIW, this affects Helper and Mailer tests with nested describe blocks as well.

Problems after upgrading to MTSR 5.1

I've just upgraded my app to Rails 4.1.8 and MTSR 5.1. I was on Rails 4.0.2 and MTSR 4.7. Now, when I try to run my test suite I get:

$ rake test
rake aborted!
NameError: method `describe' not defined in Class
/home/ian/workspace/hpi-explorer/config/environment.rb:5:in `<top (required)>'
/home/ian/workspace/hpi-explorer/test/test_helper.rb:2:in `require'
/home/ian/workspace/hpi-explorer/test/test_helper.rb:2:in `<top (required)>'
/home/ian/workspace/hpi-explorer/test/helpers/download_helper_test.rb:1:in `require'
/home/ian/workspace/hpi-explorer/test/helpers/download_helper_test.rb:1:in `<top (required)>'
Tasks: TOP => test:run => test:units

I'm not sure where to look for the source of the error. I've looked at the mtsr_integration project, and while my project is (naturally) a bit different, I can't see what the significant differences are.

My Gemfile has:

group :test do
  gem 'capybara-webkit', '~> 1.1'
  gem 'minitest-capybara', '~> 0.7'
  gem 'minitest-spec-rails', '~> 5.1'
  gem 'json_expressions', "~> 0.8"
  gem 'vcr'
  gem 'minitest-vcr'
  gem 'webmock'
end

My test_helper.rb:

ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)

require 'minitest/autorun'

class AcceptanceTest < Minitest::Unit::TestCase
  include Capybara::DSL
  include Minitest::Capybara::Assertions

  def teardown
    Capybara.reset_session!
    Capybara.use_default_driver
  end
end

class AcceptanceSpec < AcceptanceTest
  extend Minitest::Spec::DSL
end

VCR.configure do |c|
  c.cassette_library_dir = 'fixtures/vcr_cassettes'
  c.hook_into :webmock
end

Does anything stand out as being an obvious problem, or do I need to provide more info or do more investigation?

Thanks,
Ian

Error when generating scaffold with --skip-stylesheets

Hi, when creating a new scaffold with the option of --skip-stylesheets i get the following error:

/Users/eka/dev/web/sites/redditpics/.gs/gems/minitest-4.7.5/lib/minitest/unit.rb:1037:in `block in process_args': invalid option: --skip-stylesheets (OptionParser::InvalidOption)
        from /Users/eka/dev/web/sites/redditpics/.gs/gems/minitest-4.7.5/lib/minitest/unit.rb:1016:in `new'
        from /Users/eka/dev/web/sites/redditpics/.gs/gems/minitest-4.7.5/lib/minitest/unit.rb:1016:in `process_args'
        from /Users/eka/dev/web/sites/redditpics/.gs/gems/minitest-4.7.5/lib/minitest/unit.rb:1066:in `_run'
        from /Users/eka/dev/web/sites/redditpics/.gs/gems/minitest-4.7.5/lib/minitest/unit.rb:1059:in `run'
        from /Users/eka/dev/web/sites/redditpics/.gs/gems/minitest-4.7.5/lib/minitest/unit.rb:795:in `block in autorun'

Any clue?

Run tests in folder other than controllers/models/etc. by default

I'd like my rake test to run the tests in folder called 'imports'. I've looked for solutions on SO and here, but can't find one.

If you use minitest-rails you can do this: MiniTest::Rails::Testing.default_tasks << 'lib'
What's the best way to go about this with minitest-spec-rails?

load after the environment is loaded

it would be nice to leave the original order of things alone, so we can do load environment -> load test helpers, basically turning the railtie setting into a require / making things less involved/tied to rails startup process

Version dependencies not friendly

It would be nice if I could use minitest-spec-rails with latest minitest and rails 4.0.x (or 4.1.x)
I'd imagine most people would want a recent version of minitest without having to commit to an unreleased version of rails.

Rails 3.2.22.2 / MiniSpecRails 4.7.9 - ActionController::TestCase incompatible with "tests" method

I have the need to test certain controllers under non-normal circumstances. These tests are not named according to controller name, and are throwing errors because of that. In ActionController::TestCase there's a class method called "tests" that is supposed to enable you to describe the test case in question. It's not working in MiniSpecTest.

# working
class CompaniesControllerTest < ActionController::TestCase
  def test_truth
    assert true
  end
end

# not working
class SpecialCompaniesControllerTest < ActionController::TestCase
  tests CompaniesController
  def test_truth
    assert true
  end
end

Renaming the class to 'SpecialCompaniesControllerTest' starts throwing weird errors like so:

E /vendor/ruby/2.1.0/gems/actionpack-3.2.22.2/lib/action_controller/test_case.rb @ 378
SpecialCompaniesControllerTest
  test_truth
  !! ArgumentError
  controller class must be a String, Symbol, or Class
  /Users/seth/Work/cashboard/app/vendor/ruby/2.1.0/gems/actionpack-3.2.22.2/lib/action_controller/test_case.rb:378:in `tests'

E /vendor/ruby/2.1.0/gems/activerecord-3.2.22.2/lib/active_record/fixtures.rb @ 878
SpecialCompaniesControllerTest
  test_truth
  !! NoMethodError
  undefined method `each' for nil:NilClass
  /Users/seth/Work/cashboard/app/vendor/ruby/2.1.0/gems/activerecord-3.2.22.2/lib/active_record/fixtures.rb:878:in `teardown_fixtures'
  /Users/seth/Work/cashboard/app/vendor/ruby/2.1.0/gems/activesupport-3.2.22.2/lib/active_support/callbacks.rb:405:in `_run__3656525468224606978__teardown__2713731447860676535__callbacks'
  /Users/seth/Work/cashboard/app/vendor/ruby/2.1.0/gems/activesupport-3.2.22.2/lib/active_support/callbacks.rb:405:in `__run_callback'
  /Users/seth/Work/cashboard/app/vendor/ruby/2.1.0/gems/activesupport-3.2.22.2/lib/active_support/callbacks.rb:385:in `_run_teardown_callbacks'
  /Users/seth/Work/cashboard/app/vendor/ruby/2.1.0/gems/activesupport-3.2.22.2/lib/active_support/callbacks.rb:81:in `run_callbacks'

undefined method `protected_instance_variables=' for ActionController::Base:Class

when I launch my test, i got

/home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/action_controller/base.rb:252:in `<class:Base>': undefined method `protected_instance_variables=' for ActionController::Base:Class (NoMethodError)
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/action_controller/base.rb:163:in `<module:ActionController>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/action_controller/base.rb:4:in `<top (required)>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/action_view/test_case.rb:9:in `<class:TestCase>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/action_view/test_case.rb:8:in `<module:ActionView>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/action_view/test_case.rb:6:in `<top (required)>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/minitest-spec-rails-4.3.8/lib/minitest-spec-rails/init/action_view.rb:39:in `<top (required)>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:228:in `require'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:228:in `block in require'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:228:in `require'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/minitest-spec-rails-4.3.8/lib/minitest-spec-rails/railtie.rb:10:in `block (2 levels) in <class:Railtie>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/action_view/base.rb:199:in `<class:Base>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/action_view/base.rb:131:in `<module:ActionView>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/action_view/base.rb:6:in `<top (required)>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:228:in `require'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:228:in `block in require'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:228:in `require'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/abstract_controller/view_paths.rb:1:in `<top (required)>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/abstract_controller/rendering.rb:34:in `<module:Rendering>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/abstract_controller/rendering.rb:32:in `<module:AbstractController>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionpack-4.0.0.beta1/lib/abstract_controller/rendering.rb:4:in `<top (required)>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionmailer-4.0.0.beta1/lib/action_mailer/base.rb:367:in `<class:Base>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionmailer-4.0.0.beta1/lib/action_mailer/base.rb:362:in `<module:ActionMailer>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/actionmailer-4.0.0.beta1/lib/action_mailer/base.rb:8:in `<top (required)>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/sidekiq-2.7.5/lib/sidekiq/rails.rb:8:in `hook_rails!'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/sidekiq-2.7.5/lib/sidekiq/rails.rb:16:in `block in <class:Rails>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/railties-4.0.0.beta1/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/railties-4.0.0.beta1/lib/rails/initializable.rb:30:in `run'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/railties-4.0.0.beta1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/xenor/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from /home/xenor/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /home/xenor/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from /home/xenor/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from /home/xenor/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from /home/xenor/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from /home/xenor/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/railties-4.0.0.beta1/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/railties-4.0.0.beta1/lib/rails/application.rb:213:in `initialize!'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@gwc-web/gems/railties-4.0.0.beta1/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/xenor/wwwroot/gwc-web/config/environment.rb:5:in `<top (required)>'
    from /home/xenor/wwwroot/gwc-web/test/test_helper.rb:2:in `require'
    from /home/xenor/wwwroot/gwc-web/test/test_helper.rb:2:in `<top (required)>'
    from /home/xenor/wwwroot/gwc-web/test/helpers/registration_helper_test.rb:1:in `require'
    from /home/xenor/wwwroot/gwc-web/test/helpers/registration_helper_test.rb:1:in `<top (required)>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:10:in `require'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:9:in `each'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:4:in `select'
    from /home/xenor/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:4:in `<main>'
Errors running test:units! #<RuntimeError: Command failed with status (1): [ruby -I"lib:test" -I"/home/xenor/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.3/lib" "/home/xenor/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb" "test/{models,helpers,unit}/**/*_test.rb" ]>

any clue ?

I am using rails 4.0.0-beta1 and ruby 2.0.0

Testing without matchers?

In the readme file you state: "I highly suggest that you stay away from matchers since MiniTest::Spec gives you all the tools you need to write good tests."

Without matchers, how would be the correct way to test that a page has an h1 of "home"?

Here's how to do it with a matcher: must_have_selector('h1', text: 'Sign up'). I can't seem to figure out the alternative.

Support for rr mocking

I got a problem with rr mocks. I have test like below.

   describe "#valid?" do
        describe "and credentials are not valid" do
          before do
            mock(NokautSoapApi::User).authenticate(login, password) do
              raise NokautSoapApi::User::InvalidPassword.new("Invalid password")
            end
          end

          it("returns false") { authentication.valid?.must_equal false }
          it "set errors" do
            #mock(NokautSoapApi::User).authenticate(login, password) do
            #  raise NokautSoapApi::User::InvalidPassword.new("Invalid password")
            #end
            authentication.valid?
            authentication.errors.must_include "Invalid Password"
          end
        end

        describe "and credentials are valid" do
          before do
            mock(NokautSoapApi::User).authenticate(login, password) { true }
          end

          it "returns true" do
            authentication.valid?.must_equal true
          end
        end
      end
    end

My problem is it fails because mocks are not working. When I uncomment mock inside "it" block withs one tests pass. Should it work this way?

Describing any class with the word "Review" errors out

I have a class that I am testing with the name UserReview which causes a TypeError with this stack trace because minitest-spec-rails treats any class that has the word view in the class name. I have traced the error here, which does a case insensitive regex on the name. From looking at the ActionView test cases, this is expected behavior, but it interferes with classes that end in view (Preview, Review, etc) that are not actually views.

Example of the issue

class UserReview
end

describe UserReview
  it 'is true' do
    true.must_equal true
  end
end

Trouble getting IntegrationTest to work

class BorrowDirectIntegrationTest < ActionDispatch::IntegrationTest
  self.use_transactional_fixtures = false
  describe "a describe block" do

    it "an example" do
      get "/some/path"
    end
  end
end
NoMethodError: undefined method `get' for #<#<Class:0x007faee1c17658>:0x007faee62ef440>

get is definitely a method in ActionDispatch::IntegrationTest, and if I don't try to use spec-style but just use Rails own test 'something' do, then it works.

Am I doing something wrong?

rails 4.1.6
minitest-spec-rails 5.1.0

test_helper.rb:

# Configure Rails Environment
ENV["RAILS_ENV"] = "test"

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

require 'vcr'
require 'webmock'
require 'minitest-vcr'

Rails.backtrace_cleaner.remove_silencers!

# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

# Load fixtures from the engine
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
  ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
end

Fixtures not working

I have a fixture named users.

When I try using the users function like this

user1 = users(:one)

It tells me the class doesn't have a users function. I've messed around with the code a bit and can't find a reason as to why this is happening.

_spec files support

This is more of a question rather than a specific issue.

What are your thoughts on supporting _spec* files as well as _test* files for the rake tests?

I understand I can do it locally on my project, but it appears redundant.

4.7.4 depends on wrong rails version

I cannot retrace that in the git history, but the released version 4.7.4 depends on rails <= 4.0. 4.7.3 depended on rails >= 3.0.

That means versions below 3.0 are now allowed (on purpose?) and especially version 4.0.1 and later are not. It is thus not working with the current rails version 4.0.1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.