Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ Added FAQ section to README

[git-p4: depot-paths = "//src/minitest/dev/": change = 8380]
  • Loading branch information...
commit 35505bc181fef85908e2e7b1e1d747341b8a44c5 1 parent 98805e3
@zenspider zenspider authored
Showing with 48 additions and 0 deletions.
  1. +48 −0 README.txt
View
48 README.txt
@@ -281,6 +281,54 @@ fixture loading:
MiniTest::Unit.runner = MiniTestWithTransactions::Unit.new
+== FAQ
+
+=== How to test SimpleDelegates?
+
+The following implementation and test:
+
+ class Worker < SimpleDelegator
+ def work
+ end
+ end
+
+ describe Worker do
+ before do
+ @worker = Worker.new(Object.new)
+ end
+
+ it "must respond to work" do
+ @worker.must_respond_to :work
+ end
+ end
+
+outputs a failure:
+
+ 1) Failure:
+ Worker#test_0001_must respond to work [bug11.rb:16]:
+ Expected #<Object:0x007f9e7184f0a0> (Object) to respond to #work.
+
+Worker is a SimpleDelegate which in 1.9+ is a subclass of BasicObject.
+Expectations are put on Object (one level down) so the Worker
+(SimpleDelegate) hits `method_missing` and delegates down to the
+`Object.new` instance. That object doesn't respond to work so the test
+fails.
+
+You can bypass `SimpleDelegate#method_missing` by extending the worker
+with `MiniTest::Expectations`. You can either do that in your setup at
+the instance level, like:
+
+ before do
+ @worker = Worker.new(Object.new)
+ @worker.extend MiniTest::Expectations
+ end
+
+or you can extend the Worker class (within the test file!), like:
+
+ class Worker
+ include ::MiniTest::Expectations
+ end
+
== Known Extensions:
capybara_minitest_spec :: Bridge between Capybara RSpec matchers and MiniTest::Spec expectations (e.g. page.must_have_content('Title')).

2 comments on commit 35505bc

@wojtekmach

thanks!

@zenspider
Owner

No prob. Lemme know if it is missing something.

Please sign in to comment.
Something went wrong with that request. Please try again.