minitest

Checking for any exception

五迷三道 提交于 2020-01-15 09:09:27
问题 Using MiniTest spec, I can test that code raises a specific exception as follows: proc { foo.do_bar }.must_raise SomeException But, I don't care what the specific exception is, I just want to verify that some exception is thrown. If I, or another developer, decides to change what exception is thrown by Foo#do_bar, my test wouldn't have to change if the expected exception was specified generally enough. That is, I would like to write the test this way (Exception is an ancestor of class

What do I do with this error when I run tests in rails?

孤街浪徒 提交于 2020-01-15 03:42:09
问题 using ruby1.9.2 rails3.1.0 I am working from my netbook, so it is not my usual dev environment. I cloned a repo that I was working with on my desktop early this week. Now when I run rake test I get this error in the terminal. ^[[1;5C/home/work/.rvm/gems/ruby-1.9.2-p290@rails310/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_ /home/work/.rvm/gems/ruby-1.9.2-p290@rails310/gems/turn-0.8.3/lib/turn/autorun/minitest.rb:14:in `<top (required)>':

Globbing doesn't work with Minitest - Only one file is run

别来无恙 提交于 2020-01-04 15:14:54
问题 I have placed all my specs in specs/*.rb . However, when I run Minitest with ruby spec/**/*_spec.rb , only one file is run. What gives? 回答1: This is not minitest specific, but Ruby. You are effectively running a ruby program which knows nothing about the program being run. Ruby does not support running multiple files at once afaik, so if you want to get a similar result you could try something like: for file in spec/**/*_spec.rb; do ruby $file; done UPDATE : for what you want you should

Possible to “fail fast” when running rake test w/ minitest 5?

扶醉桌前 提交于 2020-01-03 15:31:24
问题 Is it possible to configure 'rake test' to stop running tests as soon as it hits a failure/exception? My setup: Rails 4.1 Minitest 5.3.4 Tapout (for formatting) I'd like to start the test suite and immediately stop if a test fails -- the default behavior is to keep running all the tests which, in some cases, is too much data (especially one small bug causes a ton of tests to suddenly fail.) I had a nice little setup going with the older version of Minitest (4.x) and the Turn gem by following

How to run a full MiniTest suite without Rake?

∥☆過路亽.° 提交于 2020-01-02 02:21:06
问题 Looked at this question already, and that more or less mirrors how I currently run my whole suite. Additionally, I've setup the following rake task: Rake::TestTask.new do |t| t.name = "spec:models" t.libs << "test" t.pattern = "spec/models/*_spec.rb" end But I notice when I run this using time rake spec:models , that it completes in about 2.36 seconds. If I run all the individual tests in that directory using ruby /path/to/spec.rb (all are isolated from ActiveRecord currently--no persistance

How can I mock with a block in minitest?

北城以北 提交于 2020-01-01 12:00:21
问题 Hopefully a simple question for MiniTest folks.. I have a section of code which I'll condense into an example here: class Foo def initialize(name) @sqs = Aws::SQS::Client.new @id = @sqs.create_queue( queue_name: name ).fetch(:queue_url) @poller = Aws::SQS::QueuePoller.new(@id) end def pick_first @poller.poll(idle_timeout: 60) do |message| process_msg(message) if some_condition(message) end end How can I mock/stub/something-else so that I can feed a message through to be tested by the some

In Rails why is my mail body empty only in my test?

我的梦境 提交于 2020-01-01 07:57:06
问题 I have an actionmailer class and associated overhead, it works perfectly. In my unit test (rails default minitest) however, the email body is empty. Why is that? my mailer class: class TermsMailer < ApplicationMailer default from: "info@domain.com" def notice_email(user,filename) @user = user @file = filename mail(to: "info@domain.com", subject: 'Data downloaded') end end my test: require 'test_helper' class TermsMailerTest < ActionMailer::TestCase test "notice" do email = TermsMailer.notice

Is it still advisable to test routes in Rails 4 with Minitest?

梦想与她 提交于 2020-01-01 05:18:10
问题 In Rails 3, when writing functional tests in MiniTest, I got in the habit of testing routes separately from testing my controller actions. I got the idea from the Rails Guide on Testing - Section 9: Testing Routes. However, after upgrading my application to Rails 4 I noticed that the controller action tests themselves have started balking about unknown routes if I don't supply the get|patch|post|delete method with a proper set of params. For example, given routes: # config/routes.rb namespace

Ruby Minitest: Suite- or Class- level setup?

痞子三分冷 提交于 2019-12-28 13:49:30
问题 Using the built-in Ruby Minitest framework, is there a way to run some code once before the entire suite runs, or even once before an entire TestClass runs? I see in the answer to this question that Test::Unit::after_tests can be used to run code after all tests have been run; is there a similar method to run code before all tests have run? I would like to use this functionality to initialize a test database before the tests run and tear it down after they have all run. Thanks! 回答1: This is

NoMethodError: undefined method `mock' for minitest and mocha

自作多情 提交于 2019-12-25 05:18:44
问题 I'm developing a gem for Rails 3 and came across an error in my test suit when running it under Ruby 1.8.7 at travis-ci.org: /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:874:in `_run_suite': undefined method `run' for #<TestActivist:0xb6936dd4> (NoMethodError) 69 from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:866:in `map' 70 from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:866:in `_run