Permalink
Browse files

Correctly pass/fail pending block with message expectations

- Closes #257
  • Loading branch information...
1 parent 851d199 commit 644e372968cd2f6aa641eb3584e87fb091a4e3c9 @dchelimsky dchelimsky committed Apr 13, 2011
@@ -1,28 +1,96 @@
Feature: mock with flexmock
- As an RSpec user who likes to mock
- I want to be able to use flexmock
+ Configure RSpec to use flexmock as shown in the scenarios below.
- Scenario: Mock with flexmock
- Given a file named "flexmock_example_spec.rb" with:
+ Scenario: passing message expectation
+ Given a file named "example_spec.rb" with:
"""
RSpec.configure do |config|
config.mock_framework = :flexmock
end
- describe "plugging in flexmock" do
- it "allows flexmock to be used" do
- target = Object.new
- flexmock(target).should_receive(:foo).once
- target.foo
+ describe "mocking with RSpec" do
+ it "passes when it should" do
+ receiver = flexmock('receiver')
+ receiver.should_receive(:message).once
+ receiver.message
end
+ end
+ """
+ When I run `rspec example_spec.rb`
+ Then the examples should all pass
+
+ Scenario: failing message expecation
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :flexmock
+ end
+
+ describe "mocking with RSpec" do
+ it "fails when it should" do
+ receiver = flexmock('receiver')
+ receiver.should_receive(:message).once
+ end
+ end
+ """
+ When I run `rspec example_spec.rb`
+ Then the output should contain "1 example, 1 failure"
+
+ Scenario: failing message expectation in pending block (remains pending)
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :flexmock
+ end
+
+ describe "failed message expectation in a pending block" do
+ it "is listed as pending" do
+ pending do
+ receiver = flexmock('receiver')
+ receiver.should_receive(:message).once
+ end
+ end
+ end
+ """
+ When I run `rspec example_spec.rb`
+ Then the output should contain "1 example, 0 failures, 1 pending"
+ And the exit status should be 0
+
+ Scenario: passing message expectation in pending block (fails)
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :flexmock
+ end
- describe "RSpec.configuration.mock_framework.framework_name" do
- it "returns :flexmock" do
- RSpec.configuration.mock_framework.framework_name.should eq(:flexmock)
+ describe "passing message expectation in a pending block" do
+ it "fails with FIXED" do
+ pending do
+ receiver = flexmock('receiver')
+ receiver.should_receive(:message).once
+ receiver.message
end
end
end
"""
- When I run `rspec ./flexmock_example_spec.rb`
+ When I run `rspec example_spec.rb`
+ Then the output should contain "FIXED"
+ Then the output should contain "1 example, 1 failure"
+ And the exit status should be 1
+
+ Scenario: accessing RSpec.configuration.mock_framework.framework_name
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :flexmock
+ end
+
+ describe "RSpec.configuration.mock_framework.framework_name" do
+ it "returns :flexmock" do
+ RSpec.configuration.mock_framework.framework_name.should eq(:flexmock)
+ end
+ end
+ """
+ When I run `rspec example_spec.rb`
Then the examples should all pass
@@ -1,28 +1,97 @@
Feature: mock with mocha
- As an RSpec user who likes to mock
- I want to be able to use mocha
+ Configure RSpec to use mocha as shown in the scenarios below.
- Scenario: Mock with mocha
- Given a file named "mocha_example_spec.rb" with:
+ Scenario: passing message expectation
+ Given a file named "example_spec.rb" with:
"""
RSpec.configure do |config|
config.mock_framework = :mocha
end
- describe "plugging in mocha" do
- it "allows mocha to be used" do
- target = Object.new
- target.expects(:foo).once
- target.foo
+ describe "mocking with RSpec" do
+ it "passes when it should" do
+ receiver = mock('receiver')
+ receiver.expects(:message).once
+ receiver.message
end
+ end
+ """
+ When I run `rspec example_spec.rb`
+ Then the examples should all pass
+
+ Scenario: failing message expecation
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :mocha
+ end
- describe "RSpec.configuration.mock_framework.framework_name" do
- it "returns :mocha" do
- RSpec.configuration.mock_framework.framework_name.should eq(:mocha)
+ describe "mocking with RSpec" do
+ it "fails when it should" do
+ receiver = mock('receiver')
+ receiver.expects(:message).once
+ end
+ end
+ """
+ When I run `rspec example_spec.rb`
+ Then the output should contain "1 example, 1 failure"
+
+ Scenario: failing message expectation in pending block (remains pending)
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :mocha
+ end
+
+ describe "failed message expectation in a pending block" do
+ it "is listed as pending" do
+ pending do
+ receiver = mock('receiver')
+ receiver.expects(:message).once
end
end
end
"""
- When I run `rspec ./mocha_example_spec.rb`
+ When I run `rspec example_spec.rb`
+ Then the output should contain "1 example, 0 failures, 1 pending"
+ And the exit status should be 0
+
+ Scenario: passing message expectation in pending block (fails)
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :mocha
+ end
+
+ describe "passing message expectation in a pending block" do
+ it "fails with FIXED" do
+ pending do
+ receiver = mock('receiver')
+ receiver.expects(:message).once
+ receiver.message
+ end
+ end
+ end
+ """
+ When I run `rspec example_spec.rb`
+ Then the output should contain "FIXED"
+ Then the output should contain "1 example, 1 failure"
+ And the exit status should be 1
+
+ Scenario: accessing RSpec.configuration.mock_framework.framework_name
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :mocha
+ end
+
+ describe "RSpec.configuration.mock_framework.framework_name" do
+ it "returns :mocha" do
+ RSpec.configuration.mock_framework.framework_name.should eq(:mocha)
+ end
+ end
+ """
+ When I run `rspec example_spec.rb`
Then the examples should all pass
+
@@ -1,29 +1,98 @@
-@no-jruby
Feature: mock with rr
- As an RSpec user who likes to mock
- I want to be able to use rr
+ Configure RSpec to use rr as shown in the scenarios below.
- Scenario: Mock with rr
- Given a file named "rr_example_spec.rb" with:
+ Scenario: passing message expectation
+ Given a file named "example_spec.rb" with:
"""
RSpec.configure do |config|
config.mock_framework = :rr
end
- describe "plugging in rr" do
- it "allows rr to be used" do
- target = Object.new
- mock(target).foo
- target.foo
+ describe "mocking with RSpec" do
+ it "passes when it should" do
+ receiver = Object.new
+ mock(receiver).message
+ receiver.message
end
+ end
+ """
+ When I run `rspec example_spec.rb`
+ Then the examples should all pass
+
+ Scenario: failing message expecation
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :rr
+ end
+
+ describe "mocking with RSpec" do
+ it "fails when it should" do
+ receiver = Object.new
+ mock(receiver).message
+ end
+ end
+ """
+ When I run `rspec example_spec.rb`
+ Then the output should contain "1 example, 1 failure"
+
+ Scenario: failing message expectation in pending block (remains pending)
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :rr
+ end
+
+ describe "failed message expectation in a pending block" do
+ it "is listed as pending" do
+ pending do
+ receiver = Object.new
+ mock(receiver).message
+ end
+ end
+ end
+ """
+ When I run `rspec example_spec.rb`
+ Then the output should contain "1 example, 0 failures, 1 pending"
+ And the exit status should be 0
+
+ Scenario: passing message expectation in pending block (fails)
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :rr
+ end
- describe "RSpec.configuration.mock_framework.framework_name" do
- it "returns :rr" do
- RSpec.configuration.mock_framework.framework_name.should eq(:rr)
+ describe "passing message expectation in a pending block" do
+ it "fails with FIXED" do
+ pending do
+ receiver = Object.new
+ mock(receiver).message
+ receiver.message
end
end
end
"""
- When I run `rspec rr_example_spec.rb`
+ When I run `rspec example_spec.rb`
+ Then the output should contain "FIXED"
+ Then the output should contain "1 example, 1 failure"
+ And the exit status should be 1
+
+ Scenario: accessing RSpec.configuration.mock_framework.framework_name
+ Given a file named "example_spec.rb" with:
+ """
+ RSpec.configure do |config|
+ config.mock_framework = :rr
+ end
+
+ describe "RSpec.configuration.mock_framework.framework_name" do
+ it "returns :rr" do
+ RSpec.configuration.mock_framework.framework_name.should eq(:rr)
+ end
+ end
+ """
+ When I run `rspec example_spec.rb`
Then the examples should all pass
+
+
Oops, something went wrong. Retry.

0 comments on commit 644e372

Please sign in to comment.