Skip to content
This repository
Browse code

add some doc to stub_chain.feature

  • Loading branch information...
commit fee8d4da93b2610dd3dd7996cfcf992cc9455141 1 parent f5f187e
David Chelimsky authored August 31, 2010

Showing 1 changed file with 23 additions and 10 deletions. Show diff stats Hide diff stats

  1. 33  features/stubs/stub_chain.feature
33  features/stubs/stub_chain.feature
... ...
@@ -1,31 +1,44 @@
1 1
 Feature: stub_chain
2 2
 
  3
+  The stub_chain method lets you to stub a chain of methods in one statement.
  4
+  Method chains are considered a design smell, but it's not really the method
  5
+  chain that is the problem - it's the dependency chain represented by a chain
  6
+  of messages to different objects:
  7
+
  8
+    foo.get_bar.get_baz
  9
+
  10
+  This is a Law of Demeter violation if get_bar() returns an object other than
  11
+  foo, and get_baz() returns yet another object.
  12
+
  13
+  Fluent interfaces look similar from a caller's perspective, but don't
  14
+  represent a dependency chain (the caller depends only on the object it is
  15
+  calling). Consider this common example from Ruby on Rails:
  16
+
  17
+    Article.recent.by(current_user)
  18
+
  19
+  The recent() and by() methods return the same object, so this is not
  20
+  a Law of Demeter violation.
  21
+
3 22
   Scenario: stub a chain of methods
4 23
     Given a file named "stub_chain_spec.rb" with:
5 24
       """
6 25
       describe "stubbing a chain of methods" do
7 26
         subject { Object.new }
8 27
 
9  
-        context "given symbols as methods" do
10  
-
  28
+        context "given symbols representing methods" do
11 29
           it "returns the correct value" do
12 30
             subject.stub_chain(:one, :two, :three).and_return(:four)
13  
-
14  
-            subject.one.two.three.should eql(:four)
  31
+            subject.one.two.three.should eq(:four)
15 32
           end
16  
-
17 33
         end
18 34
 
19 35
         context "given a string of methods separated by dots" do
20  
-
21 36
           it "returns the correct value" do
22 37
             subject.stub_chain("one.two.three").and_return(:four)
23  
-
24  
-            subject.one.two.three.should eql(:four)
  38
+            subject.one.two.three.should eq(:four)
25 39
           end
26  
-
27 40
         end
28 41
       end
29 42
       """
30 43
     When I run "rspec stub_chain_spec.rb"
31  
-    Then the output should contain "2 examples, 0 failures"
  44
+    Then the output should contain "2 examples, 0 failures"

0 notes on commit fee8d4d

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