RSpec Code Examples

 

 

pending spec with no implementation
is pending (PENDING: Not yet implemented)
pending command with block format
with content that would fail
is pending (PENDING: No reason given)
behaves like shared
is marked as pending but passes n.nnnns
Expected example to fail since it is pending, but it passed.
./spec/rspec/core/resources/formatter_specs.rb:4
2
3RSpec.shared_examples_for "shared" do
4  it "is marked as pending but passes" do
5    pending
6    expect(1).to eq(1)
passing spec
passesn.nnnns
failing spec
fails n.nnnns
expected: 2
     got: 1

(compared using ==)
./spec/rspec/core/resources/formatter_specs.rb:33:in `block (2 levels) in <top (required)>'
31RSpec.describe "failing spec" do
32  it "fails" do
33    expect(1).to eq(2)
34  end
35end
a failing spec with odd backtraces
fails with a backtrace that has no file n.nnnns
foo
./spec/rspec/core/resources/formatter_specs.rb:41:in `block (2 levels) in <top (required)>'
39    require 'erb'
40
41    ERB.new("<%= raise 'foo' %>").result
42  end
fails with a backtrace containing an erb file n.nnnns
Exception
/foo.html.erb:1:in `<main>': foo (RuntimeError)
   from /lib/ruby/1.9.1/erb.rb:753:in `eval'

  Showing full backtrace because every line was filtered out.
  See docs for RSpec::Configuration#backtrace_exclusion_patterns and
  RSpec::Configuration#backtrace_inclusion_patterns for more information.
-1# Couldn't get snippet for 
with a `nil` backtrace
raises n.nnnns
boom
-1# Couldn't get snippet for