Skip to content

Commit

Permalink
Separate common code from test/unit code to make it easier to use oth…
Browse files Browse the repository at this point in the history
…er testing tools like Cucumber
  • Loading branch information
aslakhellesoy committed Oct 13, 2008
1 parent 55221fc commit ea6db6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 8 additions & 0 deletions lib/sinatra/test/common.rb
@@ -0,0 +1,8 @@
Sinatra::Application.default_options.merge!(
:env => :test,
:run => false,
:raise_errors => true,
:logging => false
)

Sinatra.application = nil
10 changes: 1 addition & 9 deletions lib/sinatra/test/unit.rb
@@ -1,13 +1,5 @@
require 'test/unit'
require File.dirname(__FILE__) + '/methods'
require File.dirname(__FILE__) + '/common'

Test::Unit::TestCase.send(:include, Sinatra::Test::Methods)

Sinatra::Application.default_options.merge!(
:env => :test,
:run => false,
:raise_errors => true,
:logging => false
)

Sinatra.application = nil

3 comments on commit ea6db6d

@bmizerany
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m confused. How does this help you with Cucumber? Do you have an example of how you use Cucumber with this patch?

@aslakhellesoy
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Blake – sorry for the late reply – I saw this comment just now.

The example is here: http://github.com/aslakhellesoy/cucumber/wikis/sinatra

It lets me enable the sinatra test environment without having to activate Test::Unit – it interferes with cucumber (setting up exit hooks and what not).

Of course – I could always just copy the lines i factored out, but I prefer to keep things DRY in this case. WDYT?

@raggi
Copy link

@raggi raggi commented on ea6db6d Dec 2, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know cucumber, but I’d imagine this is related to bad magic.

I could once again beg that everyone stops using at_exit hooks, but you all already know that opinion, and your choices are your own.

I’d recommend just using the following excerpt from my general helper.rb that I use with all bacon projects:

  1. Disable test/unit and rspec from running, in case loaded by broken tools.
    Test::Unit.run = false if defined?(Test::Unit)
    Spec::run = false if defined?(Spec) && Spec::respond_to?(:run=)

HTH

Please sign in to comment.