minitest

Minitest and Rspec [closed]

删除回忆录丶 提交于 2019-12-20 08:34:09
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . 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

Rails minitest, database cleaner how to turn use_transactional_fixtures = false

自闭症网瘾萝莉.ら 提交于 2019-12-20 02:56:19
问题 i would like to disable use_transactional_fixtures = false in ministest to catch after_commit callback. What and where should i set-up? 回答1: 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

Why is my rake task running twice in my test?

ε祈祈猫儿з 提交于 2019-12-19 07:35:20
问题 I have a rake task test that I setup following the only examples I could find online. It looks like this: require 'test_helper' require 'minitest/mock' require 'rake' class TestScrapeWelcome < ActiveSupport::TestCase def setup Rake.application.init Rake.application.load_rakefile @task = Rake::Task['scrape:scrape'] @task.reenable end def teardown Rake::Task.clear end test "scraping text and sending to elasticsearch" do mocked_client = Minitest::Mock.new get_fixtures.each_with_index do |arg,i|

Anonymous controller in Minitest w/ Rails

孤者浪人 提交于 2019-12-19 04:47:41
问题 While converting from RSpec to Minitest I ran into a slight issue that Google has not helped with one bit, and that's figuring out how to do something like this: describe ApplicationController do controller do def index render nothing: true end end it "should catch bad slugs" do get :index, slug: "bad%20slug" response.code.should eq("403") end end with Minitest. Is there a way to create anonymous controllers like this inside of Minitest or is there documentation that could help me learn how

What is the expected syntax for checking exception messages in MiniTest's assert_raises/must_raise?

萝らか妹 提交于 2019-12-18 11:14:36
问题 What is the expected syntax for checking exception messages in MiniTest's assert_raises / must_raise ? I'm trying to make an assertion something like the following, where "Foo" is the expected error message: proc { bar.do_it }.must_raise RuntimeError.new("Foo") 回答1: You can use the assert_raises assertion, or the must_raise expectation. it "must raise" do assert_raises RuntimeError do bar.do_it end -> { bar.do_it }.must_raise RuntimeError lambda { bar.do_it }.must_raise RuntimeError proc {

Before/After Suite when using Ruby MiniTest

安稳与你 提交于 2019-12-17 18:34:03
问题 Is there an alternative to RSpec's before(:suite) and after(:suite) in MiniTest? I suspect that a custom test runner is in order, however I cannot imagine it is not a common requirement, so somebody has probably implemented in. :-) 回答1: There are setup() and teardown() methods available. The documentation also lists before() and after() as being available. Edit: Are you looking to run something before each test or before or after the whole suite is finished? 回答2: As noted above in Caley's

How do I stub things in MiniTest?

青春壹個敷衍的年華 提交于 2019-12-17 17:31:47
问题 Within my test I want to stub a canned response for any instance of a class. It might look like something like: Book.stubs(:title).any_instance().returns("War and Peace") Then whenever I call @book.title it returns "War and Peace". Is there a way to do this within MiniTest? If yes, can you give me an example code snippet? Or do I need something like mocha? MiniTest does support Mocks but Mocks are overkill for what I need. 回答1: # Create a mock object book = MiniTest::Mock.new # Set the mock

How to run all tests with minitest?

情到浓时终转凉″ 提交于 2019-12-17 15:43:13
问题 I downloaded source code for a project, found a bug, and fixed it. Now I want to run tests to find out if I have broken anything. The Tests are in minitest DSL. How do I run them all at once? I searched for applicable rake tasks etc, but I didn't find any. 回答1: Here's a link to Rake::TestTask. There is an example in the page to get you started. I'll post another one that I'm using right now for a gem: require 'rake/testtask' Rake::TestTask.new do |t| t.pattern = "spec/*_spec.rb" end As you

Migrating from RSpec to Minitest::Spec?

隐身守侯 提交于 2019-12-14 00:46:11
问题 Is there a strategy or set of steps to follow to migrate from RSpec 2 to MiniTest::Spec ? I'd like to take a look at doing this for a large project but I'm not sure where to begin. 回答1: I haven't used MiniTest::Spec for that long, I'm working on porting over some of our tests myself, but here are the few things I've noticed coming from RSpec: The matchers are of course different -- it's must / wont instead of should / should_not , and predicate matchers are gone so you can't say must_be_true

Rails generators not generating the proper test templates

人盡茶涼 提交于 2019-12-13 12:33:33
问题 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