Skip to content
This repository
Browse code

reorg some features

  • Loading branch information...
commit 539b0496ce0d7a68f0b732c2378d4f29f758ef2b 1 parent 822441c
David Chelimsky authored October 10, 2010
17  ...age_expectations/block_local_expectations.feature → ...ctations/block_local_expectations.feature.pending
@@ -14,27 +14,28 @@ Feature: block local expectations
14 14
       """
15 15
 
16 16
   Scenario: passing example
17  
-    Given a file named "spec/account_passing_spec.rb" with:
  17
+    Given a file named "spec/account_spec.rb" with:
18 18
       """
19 19
       require 'account'
20 20
 
21 21
       describe "account DSL" do
22 22
         it "it succeeds when the block local receives the given call" do
23  
-          Account.should_receive(:create).and_yield do |account|
  23
+          account = double("Account")
  24
+          Account.should_receive(:create).and_yield(account) do |account|
24 25
             account.should_receive(:opening_balance).with(100, :USD)
25 26
           end
26  
-          Account.create do
27  
-            opening_balance 100, :USD
  27
+          Account.create do |account|
  28
+            account.opening_balance 100, :USD
28 29
           end
29 30
         end
30 31
       end
31 32
       """
32  
-    When I run "rspec ./spec/account_passing_spec.rb"
  33
+    When I run "rspec ./spec/account_spec.rb"
33 34
     Then the output should contain "1 example, 0 failures"
34 35
     
35 36
   Scenario: failing example
36 37
     
37  
-    Given a file named "spec/account_failing_spec.rb" with:
  38
+    Given a file named "spec/account_spec.rb" with:
38 39
       """
39 40
       require 'account'
40 41
 
@@ -43,12 +44,12 @@ Feature: block local expectations
43 44
           Account.should_receive(:create).and_yield do |account|
44 45
             account.should_receive(:opening_balance).with(100, :USD)
45 46
           end
46  
-          Account.create do
  47
+          Account.create do |account|
47 48
             # opening_balance is not called here
48 49
           end
49 50
         end
50 51
       end
51 52
       """
52 53
 
53  
-    When I run "rspec ./spec/account_failing_spec.rb"
  54
+    When I run "rspec ./spec/account_spec.rb"
54 55
     Then the output should contain "1 example, 1 failure"
94  features/message_expectations/expect_message.feature
... ...
@@ -0,0 +1,94 @@
  1
+Feature: Expect a message
  2
+
  3
+  Use should_receive() to set an expectation that a receiver should receive a
  4
+  message before the example is completed.
  5
+
  6
+  Scenario: expect a message
  7
+    Given a file named "spec/account_spec.rb" with:
  8
+      """
  9
+      require "account"
  10
+
  11
+      describe Account do
  12
+        context "when closed" do
  13
+          it "logs an account closed message" do
  14
+            logger = double("logger")
  15
+            account = Account.new
  16
+            account.logger = logger
  17
+
  18
+            logger.should_receive(:account_closed)
  19
+
  20
+            account.close
  21
+          end
  22
+        end
  23
+      end
  24
+      """
  25
+    And a file named "lib/account.rb" with:
  26
+      """
  27
+      class Account
  28
+        attr_accessor :logger
  29
+
  30
+        def close
  31
+          logger.account_closed
  32
+        end
  33
+      end
  34
+      """
  35
+    When I run "rspec spec/account_spec.rb"
  36
+    Then the output should contain "1 example, 0 failures"
  37
+
  38
+  Scenario: expect a message with an argument
  39
+    Given a file named "spec/account_spec.rb" with:
  40
+      """
  41
+      require "account"
  42
+
  43
+      describe Account do
  44
+        context "when closed" do
  45
+          it "logs an account closed message" do
  46
+            logger = double("logger")
  47
+            account = Account.new
  48
+            account.logger = logger
  49
+
  50
+            logger.should_receive(:account_closed).with(account)
  51
+
  52
+            account.close
  53
+          end
  54
+        end
  55
+      end
  56
+      """
  57
+    And a file named "lib/account.rb" with:
  58
+      """
  59
+      class Account
  60
+        attr_accessor :logger
  61
+
  62
+        def close
  63
+          logger.account_closed(self)
  64
+        end
  65
+      end
  66
+      """
  67
+    When I run "rspec spec/account_spec.rb"
  68
+    Then the output should contain "1 example, 0 failures"
  69
+
  70
+  Scenario: provide a return value
  71
+    Given a file named "message_expectation_spec.rb" with:
  72
+      """
  73
+      describe "a message expectation" do
  74
+        context "with a return value" do
  75
+          context "specified in a block" do
  76
+            it "returns the specified value" do
  77
+              receiver = double("receiver")
  78
+              receiver.should_receive(:message) { :return_value }
  79
+              receiver.message.should eq(:return_value)
  80
+            end
  81
+          end
  82
+
  83
+          context "specified with and_return" do
  84
+            it "returns the specified value" do
  85
+              receiver = double("receiver")
  86
+              receiver.should_receive(:message).and_return(:return_value)
  87
+              receiver.message.should eq(:return_value)
  88
+            end
  89
+          end
  90
+        end
  91
+      end
  92
+      """
  93
+    When I run "rspec message_expectation_spec.rb"
  94
+    Then the output should contain "2 examples, 0 failures"
2  features/message_expectations/warn_when_expectation_is_set_on_nil.feature
... ...
@@ -1,4 +1,4 @@
1  
-Feature: warn when expectation is set on nil
  1
+Feature: Warn when expectation is set on nil
2 2
 
3 3
   Scenario: nil instance variable
4 4
     Given a file named "example_spec.rb" with:
2  features/configuration.feature → features/outside_rspec/configuration.feature
... ...
@@ -1,4 +1,4 @@
1  
-Feature: configure a test framework to use rspec-mocks
  1
+Feature: Configure any test framework to use rspec-mocks
2 2
 
3 3
   Test frameworks that want to use rspec-mocks can use
4 4
   RSpec::Mocks::setup(self) to hook into rspec-mocks. Doing so adds the
55  features/stubs/simple_return_value.feature
... ...
@@ -0,0 +1,55 @@
  1
+Feature: Stub with simple return value
  2
+
  3
+  Use the stub() method on a test double or a real object to tell the object to
  4
+  return a value (or values) in response to a given message. If the message is
  5
+  never received, nothing happens.
  6
+
  7
+  Scenario: simple stub with no return value
  8
+    Given a file named "example_spec.rb" with:
  9
+      """
  10
+      describe "a simple stub with no return value specified" do
  11
+        let(:receiver) { double("receiver") }
  12
+
  13
+        it "returns nil" do
  14
+          receiver.stub(:message)
  15
+          receiver.message.should be(nil)
  16
+        end
  17
+
  18
+        it "quietly carries on when not called" do
  19
+          receiver.stub(:message)
  20
+        end
  21
+      end
  22
+      """
  23
+    When I run "rspec example_spec.rb"
  24
+    Then the output should contain "0 failures"
  25
+
  26
+  Scenario: single return value
  27
+    Given a file named "example_spec.rb" with:
  28
+      """
  29
+      describe "a simple stub with a return value" do
  30
+        context "specified in a block" do
  31
+          it "returns the specified value" do
  32
+            receiver = double("receiver")
  33
+            receiver.stub(:message) { :return_value }
  34
+            receiver.message.should eq(:return_value)
  35
+          end
  36
+        end
  37
+
  38
+        context "specified in the double declaration" do
  39
+          it "returns the specified value" do
  40
+            receiver = double("receiver", :message => :return_value)
  41
+            receiver.message.should eq(:return_value)
  42
+          end
  43
+        end
  44
+
  45
+        context "specified with and_return" do
  46
+          it "returns the specified value" do
  47
+            receiver = double("receiver")
  48
+            receiver.stub(:message).and_return(:return_value)
  49
+            receiver.message.should eq(:return_value)
  50
+          end
  51
+        end
  52
+      end
  53
+      """
  54
+    When I run "rspec example_spec.rb"
  55
+    Then the output should contain "0 failures"
2  features/stubs/stub_chain.feature
... ...
@@ -1,4 +1,4 @@
1  
-Feature: stub_chain
  1
+Feature: Stub a chain of methods
2 2
 
3 3
   The stub_chain method lets you to stub a chain of methods in one statement.
4 4
   Method chains are considered a design smell, but it's not really the method
14  features/stubs/stub_implementation.feature
... ...
@@ -1,15 +1,11 @@
1  
-Feature: stub implementation
  1
+Feature: Stub with substitute implementation
2 2
 
3  
-  As an rspec user, I want to stub a complete implementation, not just a
4  
-  return value.
  3
+  You can stub an implementation of a method (a.k.a. fake) by passing a block
  4
+  to the stub() method.
5 5
   
6 6
   Scenario: stub implementation
7 7
     Given a file named "stub_implementation_spec.rb" with:
8 8
       """
9  
-      RSpec.configure do |c|
10  
-        c.mock_with :rspec
11  
-      end
12  
-
13 9
       describe "a stubbed implementation" do
14 10
         it "works" do
15 11
           object = Object.new
@@ -21,8 +17,8 @@ Feature: stub implementation
21 17
             end
22 18
           end
23 19
           
24  
-          object.foo(:this).should == "got this"
25  
-          object.foo(:that).should == "got that"
  20
+          object.foo(:this).should eq("got this")
  21
+          object.foo(:that).should eq("got that")
26 22
         end
27 23
       end
28 24
       """

0 notes on commit 539b049

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