How do I stub things in MiniTest?

# Create a mock object book = MiniTest::Mock.new # Set the mock to expect :title, return “War and Piece” # (note that unless we call book.verify, minitest will # not check that :title was called) book.expect :title, “War and Piece” # Stub Book.new to return the mock object # (only within the scope of the … Read more

How to run all tests with minitest?

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 can see, I assume that my files are all in /lib and that my specs are … Read more

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

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 { bar.do_it }.must_raise RuntimeError end If you need to test something on the error object, you can get it from the assertion or expectation like … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)