minitest

Rails Minitest crashing when tests fail

牧云@^-^@ 提交于 2019-12-10 13:34:36
问题 Minitest crashes every time a test fails when I run rails test (Rails 5 and Ruby 2.4.2). For example, I forced a simple test to fail by switching the assert to assert_not : Failure: TransactionTest#test_transaction_should_be_valid [/home/.../test/models/transaction_test.rb:11]: Expected true to be nil or false /home/.../.rvm/gems/ruby-2.4.2/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_transaction_should_be_valid' for class `Minitest::Result'

How do i get RSpec's shared examples like behavior in Ruby Test::Unit?

拟墨画扇 提交于 2019-12-10 12:55:35
问题 Is there a plugin/extension similar to shared_examples in RSpec for Test::Unit tests? 回答1: If you are using rails (or just active_support), use a Concern. require 'active_support/concern' module SharedTests extend ActiveSupport::Concern included do # This way, test name can be a string :) test 'banana banana banana' do assert true end end end If you're not using active_support, just use Module#class_eval . This technique builds on Andy H.'s answer, where he points out that: Test::Unit tests

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

岁酱吖の 提交于 2019-12-09 04:32:08
问题 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

How parallel are parallel tests in Ruby 1.9.3?

北慕城南 提交于 2019-12-08 19:44:22
问题 In Ruby 1.9.3, you're allowed to run multiple test cases at once. I'm not sure whether this is a feature of the language, the minitest library, or a feature of YARV, so apologies for any bad terminology. But have they eliminated the GVL for this, or does this merely mean that if one thread's doing IO, another thread can utilize the CPU? 回答1: The implementation doesn't use threads, but separate processes communicating through pipes. See e.g. this presentation. So the GVL/GIL doesn't come into

Is it still possible to use test-unit in rails 4?

可紊 提交于 2019-12-08 15:48:10
问题 After upgrading from Rails 3.2 to Rails 4, my app works, but my tests, written with test-unit, are a disaster. Minitest is rumored to be "compatible" with test-unit. However, if I attempt to use the (now bundled) Minitest, there are a raft of differences - from the assert* statement names and parameters to (clearly) many other things things both large and subtle. If I instead try to avoid Minitest and attempt to keep my test-unit gem in my Gemfile, rake test explodes, saying, undefined method

Spork + Minitest

自闭症网瘾萝莉.ら 提交于 2019-12-08 04:26:36
问题 Can anyone explain how to use Spork with Minitest. I see there's a spork-minitest gem, but it's not clear how to use it. 回答1: after you add it to your Gemfile, you can use the docs at https://github.com/sporkrb/spork and substitute in 'minitest'. so you can do spork minitest --bootstrap then to run tests, spork-minitest provides a testdrb which you can pass tests into so testdrb test/unit/something_test.rb 来源: https://stackoverflow.com/questions/9932384/spork-minitest

How do I scale the stack when debugging with byebug?

╄→尐↘猪︶ㄣ 提交于 2019-12-07 17:31:30
问题 I'm currently getting an error that looks like this: NoMethodError: undefined method `debug' for nil:NilClass /mnt/hgfs/Dropbox/Company/Project/lib/project/misc.rb:23:in `debug' /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:49:in `block in compare_addresses' /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `each' /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding

How can I generate a report that shows me my slowest running tests in Rails 3.2, Ruby 1.9?

故事扮演 提交于 2019-12-07 11:36:28
问题 I know that RSpec has the --profile option, but I'm only using MiniTest/shoulda for my current project. 回答1: You can use minitest-reporters for this purpose. This gem provide multiple reporters to see output of your tests. Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new Spec reporter shows the time which each test take to run. It shows the time on console, not as a report. 回答2: You can just use: rake TESTOPTS="-v" right out of the box. eg: rake TESTOPTS="-v" test:controllers I

Testing controllers with Minitest

独自空忆成欢 提交于 2019-12-06 20:16:23
问题 I'm trying to find examples of testing controllers with Minitest, but I've only found a couple and the just verify what template is rendered and that 'success' is returned. That doesn't seem very helpful to me. Is Minitest used to test controllers? The Railscast ( http://railscasts.com/episodes/327-minitest-with-rails ) and a couple other posts I've found seem to do model tests with Minitest and integration tests with Capybara. What about controller tests? Can they be tested with Minitest? If

Rails generators not generating the proper test templates

耗尽温柔 提交于 2019-12-06 12:13:48
My project lives here: https://github.com/jonesdeini/ICanHazSandvich I'm getting setup using minitest-rails add I can't get the generators to generate the correct test templates. from my application.rb: config.generators do |g| g.test_framework :mini_test, :spec => true, :fixture => false end even with "g.test_framework nil" I still get the same test templates generated: Output: rails g model Foo invoke active_record create db/migrate/20120827160129_create_foos.rb create app/models/foo.rb invoke test_unit create test/unit/foo_test.rb invoke factory_girl create test/factories/foos.rb Even with