1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
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, double.as_null_object)
expect(example).to 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, double.as_null_object)
expect(example).to be_pending_with('No reason given')
end
end
context "with no block" 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, double.as_null_object)
expect(example).to be_pending_with('Not yet implemented')
end
end
context "with no args" do
it "is listed as pending with the default message" do
group = RSpec::Core::ExampleGroup.describe('group') do
it "does something" do
pending
end
end
example = group.examples.first
example.run(group.new, double.as_null_object)
expect(example).to be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
end
end
context "with no docstring" do
context "declared with the pending method" do
it "does not have an auto-generated description" do
group = RSpec::Core::ExampleGroup.describe('group') do
it "checks something" do
expect((3+4)).to eq(7)
end
pending do
expect("string".reverse).to eq("gnirts")
end
end
example = group.examples.last
example.run(group.new, double.as_null_object)
expect(example.description).to match(/example at/)
end
end
context "after another example with some assertion" do
it "does not show any message" do
group = RSpec::Core::ExampleGroup.describe('group') do
it "checks something" do
expect((3+4)).to eq(7)
end
specify do
pending
end
end
example = group.examples.last
example.run(group.new, double.as_null_object)
expect(example.description).to match(/example at/)
end
end
end
context "with a message" do
it "is listed as pending with the supplied message" do
group = RSpec::Core::ExampleGroup.describe('group') do
it "does something" do
pending("just because")
end
end
example = group.examples.first
example.run(group.new, double.as_null_object)
expect(example).to be_pending_with('just because')
end
end
context "with a block" do
def run_example(*pending_args, &block)
group = RSpec::Core::ExampleGroup.describe('group') do
it "does something" do
pending(*pending_args) { block.call if block }
end
end
example = group.examples.first
example.run(group.new, double.as_null_object)
example
end
context "that fails" do
def run_example(*pending_args)
super(*pending_args) { raise ArgumentError.new }
end
context "when given no options" do
it "is listed as pending with the supplied message" do
expect(run_example("just because")).to be_pending_with("just because")
end
it "is listed as pending with the default message when no message is given" do
expect(run_example).to be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
end
end
context "when given a truthy :if option" do
it "is listed as pending with the supplied message" do
expect(run_example("just because", :if => true)).to be_pending_with("just because")
end
it "is listed as pending with the default message when no message is given" do
expect(run_example(:if => true)).to be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
end
end
context "when given a falsey :if option" do
it "runs the example and fails" do
expect(run_example( :if => false)).to fail_with(ArgumentError)
expect(run_example("just because", :if => false)).to fail_with(ArgumentError)
end
end
context "when given a truthy :unless option" do
it "runs the example and fails" do
expect(run_example( :unless => true)).to fail_with(ArgumentError)
expect(run_example("just because", :unless => true)).to fail_with(ArgumentError)
end
end
context "when given a falsey :unless option" do
it "is listed as pending with the supplied message" do
expect(run_example("just because", :unless => false)).to be_pending_with("just because")
end
it "is listed as pending with the default message when no message is given" do
expect(run_example(:unless => false)).to be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
end
end
end
context "that fails due to a failed message expectation" do
def run_example(*pending_args)
super(*pending_args) { "foo".should_receive(:bar) }
end
it "passes" do
expect(run_example("just because")).to be_pending
end
end
context "that passes" do
def run_example(*pending_args)
super(*pending_args) { expect(3).to eq(3) }
end
context "when given no options" do
it "fails with a PendingExampleFixedError" do
expect(run_example("just because")).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
expect(run_example).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
end
end
context "when given a truthy :if option" do
it "fails with a PendingExampleFixedError" do
expect(run_example("just because", :if => true)).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
expect(run_example( :if => true)).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
end
end
context "when given a falsey :if option" do
it "runs the example and it passes" do
expect(run_example( :if => false)).to pass
expect(run_example("just because", :if => false)).to pass
end
end
context "when given a truthy :unless option" do
it "runs the example and it passes" do
expect(run_example( :unless => true)).to pass
expect(run_example("just because", :unless => true)).to pass
end
end
context "when given a falsey :unless option" do
it "fails with a PendingExampleFixedError" do
expect(run_example("just because", :unless => false)).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
expect(run_example( :unless => false)).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
end
end
end
end
end
|