Confusion in cracking open the test helpers

64 views
Skip to first unread message

ak.from.w...@gmail.com

unread,
May 2, 2013, 1:17:30 PM5/2/13
to minites...@googlegroups.com
I just adopted minitest-rails as my testing gem of choice. I'm migrating from an earlier instance where the code in my "minitest_helper.rb" had the individual testing file classes inheriting from MiniTest::Spec.

It looks like the new direction is to make the test classes inherit directly from the Rails classes in anticipation of Rails 4, is that right? So I see this in the new default test_helper.rb file:

  class ActiveSupport::TestCase
    # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
    # fixtures :all

    # Add more helper methods to be used by all tests here...
  end

It sounds like I am supposed to put all of the things inside this one block that I used to have in different subclasses inheriting from MiniTest::Spec:


class MiniTest::Spec
  include ActiveSupport::Testing::SetupAndTeardown
  alias :method_name :__name__ if defined? :__name__
  DatabaseCleaner.strategy = :truncation
  before :each do
    DatabaseCleaner.clean
  end
end

class IntegrationTest < MiniTest::Spec
  include Rails.application.routes.url_helpers
  include Capybara::DSL
  register_spec_type(/integration$/, self)
end

class HelperTest < MiniTest::Spec
  include ActiveSupport::Testing::SetupAndTeardown
  include ActionView::TestCase::Behavior
  register_spec_type(/helper$/i, self)
end

How do I move these changes into the new code that cracks open ActiveSupport::TestCase? Am I supposed to even have any of these "helpers" any more, or am I just supposed to put those "includes" straight in the ActiveSupport::TestCase block? Thanks for your help. I just spent about 3 days getting most of this working with guard and spork, which was complicated, but mostly because I am new to TDD and BDD and needed to learn some of the internals of all these gems.

ak.from.w...@gmail.com

unread,
May 2, 2013, 2:31:52 PM5/2/13
to minites...@googlegroups.com
And by the way, skipped tests are throwing an obscene stack trace:

PlansHelper
     SKIP (0:00:11.734) 0001 must be a real test
          (no tests defined)
        @ /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:36:in `block in run'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:447:in `_run__2733473949102101995__setup__1641485481228920732__callbacks'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:35:in `run'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/bundler/gems/spork-minitest-spec-f619f85d0fdf/lib/spork/test_framework/minitest.rb:53:in `run_tests'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:13:in `block in run'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/spork-0.9.2/lib/spork/forker.rb:21:in `block in initialize'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/spork-0.9.2/lib/spork/forker.rb:18:in `fork'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/spork-0.9.2/lib/spork/forker.rb:18:in `initialize'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `new'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `run'
          /Users/me/.rvm/gems/ruby-1.9.3-p194@myapp/gems/spork-0.9.2/lib/spork/server.rb:48:in `run'
          /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/drb/drb.rb:1548:in `perform_without_block'
          /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/drb/drb.rb:1508:in `perform'
          /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/drb/drb.rb:1586:in `block (2 levels) in main_loop'
          /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/drb/drb.rb:1582:in `loop'
          /Users/me/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/drb/drb.rb:1582:in `block in main_loop'
Reply all
Reply to author
Forward
0 new messages