testunit

How to output names of ruby unit tests

I have a unit test (example is modified Test::Unit documentation) require 'test/unit' class TC_MyTest < Test::Unit::TestCase def test_something assert(true) end end When I execute it, I get: Loaded suite C:/test Started . Finished in 0.0 seconds. 1 tests, 1 assertions, 0 failures, 0 errors I would like to get something li...

Setup Factory Girl with Test::Unit and Shoulda

I'm trying to set up Factory Girl with Test::Unit and Shoulda in Ruby on Rails. I have installed the gem, created my factory file under the test/factories directory, and created my spec file under the test/models directory. The current error I'm getting is 'ArgumentError: No such factory: test', which leads me to believe that the test_fa...

how do you assert an exception from another ruby module is thrown? (using assert_throws)

I'm trying to write code like this: assert_throws(:ExtractionFailed) { unit.extract_from('5 x 2005')} ExtractionFailed is a trivial subclass of Exception, and under test/unit, I'm trying to assert that it is thrown when I call unit.extract_from(... bad data...) I've moved ExtractionFailed into the SemanticText module, so now test/un...

how can my gem know the path to its repository directory?

My gem semantictext has a bunch of test data that it reads for regression testing. Here's the project: http://github.com/dafydd/semantictext Here's an example test that I want to be able to run directly from the gem: http://github.com/dafydd/semantictext/blob/master/test/test%5Fdocument.rb (look for text "SANDBOX") I normally develop...

Rails fixtures - defining a table name?

Hi, At the minute all my fixtures have the same name as the table that they are intended for, because of a recent issue with rails it doesn't seem possible to have a fixture beginning with the word 'test' Does anyone know of a way to have a different fixture name and then map it to the correct table? Thanks, Andy ...

Getting access to assertion methods from a Shoulda should method

I have a shoulda macro/method that tests controller responses for XPath conditions like so: def self.should_have_xpath(path, &block) should "have an element matching the path: #{path}" do xml = REXML::Document.new @response.body match = XPath.match(xml, path) if block_given? yield match else assert match.si...

Ensure teardown runs in Test::Unit::TestCase?

I'm using Test::Unit::TestCase to write some unit tests. Currently, I have a setup function that moves and modifies some fixture files and folders on disk. (This is a necessary evil at the moment.) If a test crashes, the teardown method doesn't get called, leaving files and folders in the way. The next time I run a test, it complains...

Testing routes with host constraints via assert_routing in Rails

I have a route which I'm using constraints to check the host and then a route which is essentially the same but without the host restriction (these are really namespaces but to make things simple this example will do): match "/(:page_key)" => "namespace_one/pages#show", :constraints => proc {|env| env['SERVER_NAME'] == 'test.mysite.loc...

What command line options are available for test/unit in ruby 1.9.1?

What command line options are available if you're using the Test::Unit compatibility layer in ruby 1.9.1? Background: ruby test/test_all.rb --help provides information on what command line options are available in ruby 1.8.7, but not in ruby 1.9.1 without the test-unit gem. Looking under Test and Test::Unit for ruby 1.9.1 rdoc doesn'...

Clearance with Test::Unit

I am using Clearance for authentication with my rails app which works. But now all my unit tests fail because they redirect to the sign in page, which makes sense. Clearance seems to have helper functions for fixing that but I can only find them for Shoulda. Are there equivalent helpers for Test::Unit? ...

Can I ensure all tests contain an assertion in test/unit?

With test/unit, and minitest, is it possible to fail any test that doesn't contain an assertion, or would monkey-patching be required (for example, checking if the assertion count increased after each test was executed)? Background: I shouldn't write unit tests without assertions - at a minimum, I should use assert_nothing_raised if I'm...

Mocking an external API

I'm new to testing strategies and mocking, and I'm having a tough time figuring out how to mock a call to an external service. I'm sure it's something easy I'm missing, I just don't know what exactly. I'm using the Braintree gem to charge for subscription services through the Braintree gateway, and I wanted to mock the Customer create ...

Why am I getting a NoMethodError when I use Mocha 0.9.8 with Test::Unit 2.1.1

Has anyone seen this? Here's the error: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -rrubygems -e "require 'redgreen'" -I.:lib:test -rubygems -e "['test/unit', 'test/test_authentication.rb'].each { |f| require f }" | /Library/Ruby/Gems/1.8/gems/autotest-4.3.2/bin/unit_diff -u Load/Library/Ruby/Gems/1.8/gems/moch...

How can a person toggle the use of transactional_fixtures for one set of tests using Test::Unit?

I have some thinking-sphinx tests that I need to turn off transactions for to prevent mysql locks, but in doing so I break a lot of other tests previously written, so I need to be able to toggle the setting. I have found similar questions regarding rspec, but none for Test::Unit. I have tried self.use_transactional_fixtures = false whi...