Permalink
Browse files

:pending => 'message' assigns message (defaults to 'No reason given' …

…if :pending => true)

- defaults to 'No reason given' if :pending => true
- change default pending message to 'No reason given'
- assign 'Not yet implemented' when no block passed to example (a.k.a.
  it/specify)
- Closes #540
  • Loading branch information...
1 parent 7fa264f commit eb3d26eb290b7774ff17275c5890aa3749690770 @dchelimsky dchelimsky committed Dec 12, 2011
View
6 features/command_line/format_option.feature
@@ -56,7 +56,7 @@ Feature: --format option
something
does something that passes
does something that fails (FAILED - 1)
- does something that is pending (PENDING: Not Yet Implemented)
+ does something that is pending (PENDING: No reason given)
"""
Scenario: documentation format saved to a file
@@ -66,7 +66,7 @@ Feature: --format option
something
does something that passes
does something that fails (FAILED - 1)
- does something that is pending (PENDING: Not Yet Implemented)
+ does something that is pending (PENDING: No reason given)
"""
Scenario: multiple formats
@@ -77,5 +77,5 @@ Feature: --format option
something
does something that passes
does something that fails (FAILED - 1)
- does something that is pending (PENDING: Not Yet Implemented)
+ does something that is pending (PENDING: No reason given)
"""
View
8 features/hooks/around_hooks.feature
@@ -199,24 +199,24 @@ Feature: around hooks
When I run `rspec example_spec.rb`
Then the output should contain "1 example, 0 failure"
- Scenario: implicitly pending examples are detected as Not Yet Implemented
+ Scenario: implicitly pending examples are detected as Not yet implemented
Given a file named "example_spec.rb" with:
"""
describe "implicit pending example" do
around(:each) do |example|
example.run
end
- it "should be detected as Not Yet Implemented"
+ it "should be detected as Not yet implemented"
end
"""
When I run `rspec example_spec.rb`
Then the output should contain "1 example, 0 failures, 1 pending"
And the output should contain:
"""
Pending:
- implicit pending example should be detected as Not Yet Implemented
- # Not Yet Implemented
+ implicit pending example should be detected as Not yet implemented
+ # Not yet implemented
"""
View
10 features/pending/pending_examples.feature
@@ -13,7 +13,7 @@ Feature: pending examples
When I run `rspec example_without_block_spec.rb`
Then the exit status should be 0
And the output should contain "1 example, 0 failures, 1 pending"
- And the output should contain "Not Yet Implemented"
+ And the output should contain "Not yet implemented"
And the output should contain "example_without_block_spec.rb:2"
Scenario: pending any arbitary reason, with no block
@@ -98,13 +98,13 @@ Feature: pending examples
"""
Pending:
an example is pending using xit
- # Not Yet Implemented
+ # No reason given
# ./temporarily_pending_spec.rb:2
an example is pending using xspecify
- # Not Yet Implemented
+ # No reason given
# ./temporarily_pending_spec.rb:5
an example is pending using xexample
- # Not Yet Implemented
+ # No reason given
# ./temporarily_pending_spec.rb:8
"""
@@ -149,7 +149,7 @@ Feature: pending examples
"""
an example
checks something
- (PENDING: Not Yet Implemented)
+ (PENDING: No reason given)
"""
Scenario: conditionally pending examples
View
2 lib/rspec/core/example.rb
@@ -196,7 +196,7 @@ def finish(reporter)
reporter.example_pending self
true
elsif pending
- record_finished 'pending', :pending_message => 'Not Yet Implemented'
+ record_finished 'pending', :pending_message => String === pending ? pending : Pending::NO_REASON_GIVEN
reporter.example_pending self
true
else
View
2 lib/rspec/core/example_group.rb
@@ -54,7 +54,7 @@ def self.define_example_method(name, extra_options={})
module_eval(<<-END_RUBY, __FILE__, __LINE__)
def self.#{name}(desc=nil, *args, &block)
options = build_metadata_hash_from(args)
- options.update(:pending => true) unless block
+ options.update(:pending => RSpec::Core::Pending::NOT_YET_IMPLEMENTED) unless block
options.update(#{extra_options.inspect})
examples << RSpec::Core::Example.new(self, desc, options, block)
examples.last
View
5 lib/rspec/core/pending.rb
@@ -15,7 +15,8 @@ class PendingExampleFixedError
def pending_fixed?; true; end
end
- DEFAULT_MESSAGE = 'No reason given'
+ NO_REASON_GIVEN = 'No reason given'
+ NOT_YET_IMPLEMENTED = 'Not yet implemented'
# @overload pending()
# @overload pending(message)
@@ -71,7 +72,7 @@ def pending(*args)
return self.class.before(:each) { pending(*args) } unless example
options = args.last.is_a?(Hash) ? args.pop : {}
- message = args.first || DEFAULT_MESSAGE
+ message = args.first || NO_REASON_GIVEN
if options[:unless] || (options.has_key?(:if) && !options[:if])
return block_given? ? yield : nil
View
18 spec/rspec/core/example_spec.rb
@@ -38,29 +38,13 @@ def metadata_hash(*args)
it "returns true for pending_fixed? if pending fixed" do
example = example_group.example do
- pending("fixed") do
- true
- end
+ pending("fixed") {}
end
example_group.run
example.exception.should be_pending_fixed
end
end
- describe "#failure_type" do
- it "returns 'pending_fixed' for a PendingExampleFixedError" do
- example = example_group.example do
- pending("this message") do
- true
- end
- end
- example_group.run
- example.exception.should be_pending_fixed
- end
-
-
- end
-
describe "auto-generated example descriptions" do
let(:generated_description) { "the generated description" }
let(:rspec_example) { example_group.specify { 5.should eq(5) } }
View
2 spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html
@@ -289,7 +289,7 @@
<script type="text/javascript">makeYellow('div_group_1');</script>
<script type="text/javascript">makeYellow('example_group_1');</script>
<script type="text/javascript">moveProgressBar('14.2');</script>
- <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not Yet Implemented)</span></dd>
+ <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not yet implemented)</span></dd>
</dl>
</div>
<div id="div_group_2" class="example_group passed">
View
2 spec/rspec/core/formatters/html_formatted-1.8.7.html
@@ -289,7 +289,7 @@
<script type="text/javascript">makeYellow('div_group_1');</script>
<script type="text/javascript">makeYellow('example_group_1');</script>
<script type="text/javascript">moveProgressBar('14.2');</script>
- <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not Yet Implemented)</span></dd>
+ <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not yet implemented)</span></dd>
</dl>
</div>
<div id="div_group_2" class="example_group passed">
View
2 spec/rspec/core/formatters/html_formatted-1.9.2.html
@@ -289,7 +289,7 @@
<script type="text/javascript">makeYellow('div_group_1');</script>
<script type="text/javascript">makeYellow('example_group_1');</script>
<script type="text/javascript">moveProgressBar('14.2');</script>
- <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not Yet Implemented)</span></dd>
+ <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not yet implemented)</span></dd>
</dl>
</div>
<div id="div_group_2" class="example_group passed">
View
2 spec/rspec/core/formatters/html_formatted-1.9.3.html
@@ -289,7 +289,7 @@
<script type="text/javascript">makeYellow('div_group_1');</script>
<script type="text/javascript">makeYellow('example_group_1');</script>
<script type="text/javascript">moveProgressBar('14.2');</script>
- <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not Yet Implemented)</span></dd>
+ <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not yet implemented)</span></dd>
</dl>
</div>
<div id="div_group_2" class="example_group passed">
View
2 spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html
@@ -289,7 +289,7 @@
<script type="text/javascript">makeYellow('div_group_1');</script>
<script type="text/javascript">makeYellow('example_group_1');</script>
<script type="text/javascript">moveProgressBar('14.2');</script>
- <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not Yet Implemented)</span></dd>
+ <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not yet implemented)</span></dd>
</dl>
</div>
<div id="div_group_2" class="example_group passed">
View
2 spec/rspec/core/formatters/text_mate_formatted-1.8.7.html
@@ -289,7 +289,7 @@
<script type="text/javascript">makeYellow('div_group_1');</script>
<script type="text/javascript">makeYellow('example_group_1');</script>
<script type="text/javascript">moveProgressBar('14.2');</script>
- <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not Yet Implemented)</span></dd>
+ <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not yet implemented)</span></dd>
</dl>
</div>
<div id="div_group_2" class="example_group passed">
View
2 spec/rspec/core/formatters/text_mate_formatted-1.9.2.html
@@ -289,7 +289,7 @@
<script type="text/javascript">makeYellow('div_group_1');</script>
<script type="text/javascript">makeYellow('example_group_1');</script>
<script type="text/javascript">moveProgressBar('14.2');</script>
- <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not Yet Implemented)</span></dd>
+ <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not yet implemented)</span></dd>
</dl>
</div>
<div id="div_group_2" class="example_group passed">
View
2 spec/rspec/core/formatters/text_mate_formatted-1.9.3.html
@@ -289,7 +289,7 @@
<script type="text/javascript">makeYellow('div_group_1');</script>
<script type="text/javascript">makeYellow('example_group_1');</script>
<script type="text/javascript">moveProgressBar('14.2');</script>
- <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not Yet Implemented)</span></dd>
+ <dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not yet implemented)</span></dd>
</dl>
</div>
<div id="div_group_2" class="example_group passed">
View
44 spec/rspec/core/pending_example_spec.rb
@@ -1,14 +1,46 @@
require 'spec_helper'
describe "an example" do
+ matcher :be_pending_with do |message|
+ match do |example|
+ example.pending? && example.metadata[:execution_result][:pending_message] == message
+ end
+
+ failure_message_for_should do |example|
+ "expected: example pending with #{message.inspect}\n got: #{example.metadata[:execution_result][:pending_message].inspect}"
+ end
+ end
+
+ context "declared pending with metadata" do
+ it "uses the value assigned to :pending as the message" do
+ group = RSpec::Core::ExampleGroup.describe('group') do
+ example "example", :pending => 'just because' do
+ end
+ end
+ example = group.examples.first
+ example.run(group.new, stub.as_null_object)
+ example.should be_pending_with('just because')
+ end
+
+ it "sets the message to 'No reason given' if :pending => true" do
+ group = RSpec::Core::ExampleGroup.describe('group') do
+ example "example", :pending => true do
+ end
+ end
+ example = group.examples.first
+ example.run(group.new, stub.as_null_object)
+ example.should be_pending_with('No reason given')
+ end
+ end
+
context "with no block" do
- it "is listed as pending with 'Not Yet Implemented'" do
+ it "is listed as pending with 'Not yet implemented'" do
group = RSpec::Core::ExampleGroup.describe('group') do
it "has no block"
end
example = group.examples.first
example.run(group.new, stub.as_null_object)
- example.should be_pending_with('Not Yet Implemented')
+ example.should be_pending_with('Not yet implemented')
end
end
@@ -21,7 +53,7 @@
end
example = group.examples.first
example.run(group.new, stub.as_null_object)
- example.should be_pending_with(RSpec::Core::Pending::DEFAULT_MESSAGE)
+ example.should be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
end
end
@@ -94,7 +126,7 @@ def run_example(*pending_args)
end
it "is listed as pending with the default message when no message is given" do
- run_example.should be_pending_with(RSpec::Core::Pending::DEFAULT_MESSAGE)
+ run_example.should be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
end
end
@@ -104,7 +136,7 @@ def run_example(*pending_args)
end
it "is listed as pending with the default message when no message is given" do
- run_example(:if => true).should be_pending_with(RSpec::Core::Pending::DEFAULT_MESSAGE)
+ run_example(:if => true).should be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
end
end
@@ -128,7 +160,7 @@ def run_example(*pending_args)
end
it "is listed as pending with the default message when no message is given" do
- run_example(:unless => false).should be_pending_with(RSpec::Core::Pending::DEFAULT_MESSAGE)
+ run_example(:unless => false).should be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
end
end
end
View
14 spec/support/matchers.rb
@@ -20,16 +20,6 @@ def prepare(autotest)
end
end
-RSpec::Matchers.define :be_pending_with do |message|
- match do |example|
- example.metadata[:pending] && example.metadata[:execution_result][:pending_message] == message
- end
-
- failure_message_for_should do |example|
- "expected example to pending with #{message.inspect}, got #{example.metadata[:execution_result][:pending_message].inspect}"
- end
-end
-
RSpec::Matchers.define :fail_with do |exception_klass|
match do |example|
failure_reason(example, exception_klass).nil?
@@ -70,6 +60,6 @@ def failure_reason(example)
end
RSpec::Matchers.module_eval do
- alias have_failed_with fail_with
- alias have_passed pass
+ alias_method :have_failed_with, :fail_with
+ alias_method :have_passed, :pass
end

0 comments on commit eb3d26e

Please sign in to comment.