minitest

Include module in all MiniTest tests like in RSpec

拟墨画扇 提交于 2019-12-03 12:07:25
In RSpec I could create helper modules in /spec/support/... module MyHelpers def help1 puts "hi" end end and include it in every spec like this: RSpec.configure do |config| config.include(MyHelpers) end and use it in my tests like this: describe User do it "does something" do help1 end end How can I include a module into all MiniTest tests without repeating myself in every test? minitest does not provide a way to include or extend a module into every test class in the same way RSpec does. Your best bet is going to be to re-open the test case class (differs, depending on the minitest version

How to organize minitest/unit tests?

吃可爱长大的小学妹 提交于 2019-12-03 09:18:32
After using RSpec for several projects, I'm giving minitest/unit a go. I'm liking it so far, but I miss using describe/context blocks to group my tests/specs in a logical way. I know minitest/spec provides this functionality, but I like that minitest/unit feels a bit closer to barebones Ruby. Are there any gems that provide describe/context support for minitest/unit? Or, should I just live with my long, unorganized test files in minitest/unit? I know several folks coming from RSpec to minitest struggling with the same question. They love the ability to nest using describe/context blocks and

How to color unit tests with lib minitest or Test:Unit?

风格不统一 提交于 2019-12-03 09:03:14
问题 I would like to have unit tests output color in my dev environment. However, I can't make it work on Linux (Debian and Ubuntu). When I include the following libs: require 'minitest/autorun' require 'minitest/unit' require 'minitest/pride' I get: /usr/local/rvm/gems/ruby-1.9.2-p136/gems/minitest-2.3.1/lib/minitest/pride.rb:35:in `<top (required)>': undefined method `output' for MiniTest::Unit:Class (NoMethodError) caused by the code: MiniTest::Unit.output = PrideIO.new(MiniTest::Unit.output) I

How to use Ruby MiniTest::Spec with Rails for API integration tests?

▼魔方 西西 提交于 2019-12-03 06:04:36
问题 I'm building an app including a Rails API and want to use Ruby MiniTest::Spec to test. What's a good way to set it up? For example, good directory organization, good way to include files, etc.? I'm using the guidelines in the book Rails 3 In Action which uses RSpec and has a great chapter on APIs. The big change is preferring MiniTest::Spec. 回答1: Answering with what I've found so far in case it's helpful to other developers.... spec/api/items_spec.rb require 'spec_helper' class ItemsSpec <

How do I add gem 'minitest' to my test helper?

天涯浪子 提交于 2019-12-03 01:14:12
I am new to Ruby on Rails and testing. When I run rake test I get the following error: /Users/jarvis/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/rack-1.3.4/lib/rack/backports /uri/common_192.rb:53: warning: already initialized constant WFKV_ /Users/jarvis/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/turn-0.8.3/lib/turn/autorun /minitest.rb:14:in `<top (required)>': MiniTest v1.6.0 is out of date. (RuntimeError) `gem install minitest` and add `gem 'minitest' to you test helper. from /Users/jarvis/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/activesupport-3.1.1/lib /active_support

How to color unit tests with lib minitest or Test:Unit?

心不动则不痛 提交于 2019-12-02 23:14:50
I would like to have unit tests output color in my dev environment. However, I can't make it work on Linux (Debian and Ubuntu). When I include the following libs: require 'minitest/autorun' require 'minitest/unit' require 'minitest/pride' I get: /usr/local/rvm/gems/ruby-1.9.2-p136/gems/minitest-2.3.1/lib/minitest/pride.rb:35:in `<top (required)>': undefined method `output' for MiniTest::Unit:Class (NoMethodError) caused by the code: MiniTest::Unit.output = PrideIO.new(MiniTest::Unit.output) I have seen a working Rspec variant . Unfortunately, my Ruby knowledge is not enough to see differences.

Minitest and Rspec [closed]

和自甴很熟 提交于 2019-12-02 16:08:05
I have just watched a Railscast for Minitest. What are the pros and cons for using RSpec vs Minitest for testing a rails app? Which features will I lose converting from RSpec to Minitest? I'm one of the RSpec developers, and have never used minitest, so take my biases into account when reading this answer. By and large, RSpec's power comes from the fact that it reifies so many testing concepts into first class objects. Where Test::Unit and Minitest use simple methods for making assertions, RSpec uses first-class matcher objects that support negation, self-description and more. RSpec's examples

Rails minitest, database cleaner how to turn use_transactional_fixtures = false

℡╲_俬逩灬. 提交于 2019-12-02 01:09:05
i would like to disable use_transactional_fixtures = false in ministest to catch after_commit callback. What and where should i set-up? You have a few options. One is to create a test without transactional fixtures and hope that the changes you make to the test database isn't going to break any other tests. class SomethingTest < ActiveSupport::TestCase self.use_transactional_fixtures = false def test_something_with_after_commit # do work here, which will change your test database end end Another option you have is to keep the transactional fixtures, but invoke the after_commit callback

Rails 4 and RSpec, undefined method `assertions' in routing spec

不问归期 提交于 2019-12-01 19:46:26
问题 I'm having what appears to be the same issue as undefined method `assertions' in routing spec but I'm running Rails 4 and it is locked to minitest 5.0 or greater. Thus the solution to use minitest 4.7 I can't make work. Is there a work around for this? Where would I report the bug? 回答1: This problem is caused by a change in minitest 5.0 documented here: # https://github.com/seattlerb/minitest/issues/286 is fixed by using: gem "rspec-rails", '~> 2.14.0.rc1' in the gemfile. 来源: https:/

URI::InvalidURIError: bad URI(is not URI?) testing Rails controllers

吃可爱长大的小学妹 提交于 2019-12-01 15:20:28
I get URI::InvalidURIError testing Rails Home controller: require 'test_helper' class HomeControllerTest < ActionDispatch::IntegrationTest test "should get index" do get :index assert_response :success end end get the following error: E Error: HomeControllerTest#test_should_get_index: URI::InvalidURIError: bad URI(is not URI?): http://www.example.com:80index test/controllers/home_controller_test.rb:7:in `block in <class:HomeControllerTest>' The stack is the following: Rails 5.0.0.beta3 minitest (5.8.4) Controller tests inherit from ActionController::TestCase , while your test inherits from