rspec-core-2.14.7/ 0000755 0000041 0000041 00000000000 12261207027 013676 5 ustar www-data www-data rspec-core-2.14.7/exe/ 0000755 0000041 0000041 00000000000 12261207027 014457 5 ustar www-data www-data rspec-core-2.14.7/exe/autospec 0000755 0000041 0000041 00000000666 12261207027 016240 0 ustar www-data www-data #!/usr/bin/env ruby
require 'rspec/core/deprecation'
RSpec.warn_deprecation <<-WARNING
************************************************************
REMOVAL NOTICE: you are using behaviour that has been
removed from rspec-2.
* The 'autospec' command is no longer supported.
* Please use 'autotest' instead.
This message will be removed from a future version of rspec.
************************************************************
WARNING
rspec-core-2.14.7/exe/rspec 0000755 0000041 0000041 00000001030 12261207027 015513 0 ustar www-data www-data #!/usr/bin/env ruby
begin
require 'rspec/autorun'
rescue LoadError
$stderr.puts <<-EOS
#{'*'*50}
Could not find 'rspec/autorun'
This may happen if you're using rubygems as your package manager, but it is not
being required through some mechanism before executing the rspec command.
You may need to do one of the following in your shell:
# for bash/zsh
export RUBYOPT=rubygems
# for csh, etc.
set RUBYOPT=rubygems
For background, please see http://gist.github.com/54177.
#{'*'*50}
EOS
exit(1)
end
rspec-core-2.14.7/License.txt 0000644 0000041 0000041 00000002245 12261207027 016024 0 ustar www-data www-data (The MIT License)
Copyright (c) 2009 Chad Humphries, David Chelimsky
Copyright (c) 2006 David Chelimsky, The RSpec Development Team
Copyright (c) 2005 Steven Baker
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rspec-core-2.14.7/features/ 0000755 0000041 0000041 00000000000 12261207027 015514 5 ustar www-data www-data rspec-core-2.14.7/features/metadata/ 0000755 0000041 0000041 00000000000 12261207027 017274 5 ustar www-data www-data rspec-core-2.14.7/features/metadata/described_class.feature 0000644 0000041 0000041 00000001004 12261207027 023755 0 ustar www-data www-data Feature: described class
If the first argument to the outermost example group is a class, the class is
exposed to each example via the described_class() method.
Scenario: access the described class from the example
Given a file named "spec/example_spec.rb" with:
"""ruby
describe Fixnum do
it "is available as described_class" do
described_class.should eq(Fixnum)
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the example should pass
rspec-core-2.14.7/features/metadata/user_defined.feature 0000644 0000041 0000041 00000007606 12261207027 023316 0 ustar www-data www-data Feature: User-defined metadata
You can attach user-defined metadata to any example group or example.
Pass a hash as the last argument (before the block) to `describe`,
`context` or `it`. RSpec supports many configuration options that apply
only to certain examples or groups based on the metadata.
Metadata defined on an example group is available (and can be overridden)
by any sub-group or from any example in that group or a sub-group.
In addition, there is a configuration option (which will be the default
behavior in RSpec 3) that allows you to specify metadata using just
symbols:
```ruby
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
end
```
Each symbol passed as an argument to `describe`, `context` or `it` will
be a key in the metadata hash, with a corresponding value of `true`.
Scenario: define group metadata using a hash
Given a file named "define_group_metadata_with_hash_spec.rb" with:
"""ruby
describe "a group with user-defined metadata", :foo => 17 do
it 'has access to the metadata in the example' do
example.metadata[:foo].should eq(17)
end
it 'does not have access to metadata defined on sub-groups' do
example.metadata.should_not include(:bar)
end
describe 'a sub-group with user-defined metadata', :bar => 12 do
it 'has access to the sub-group metadata' do
example.metadata[:foo].should eq(17)
end
it 'also has access to metadata defined on parent groups' do
example.metadata[:bar].should eq(12)
end
end
end
"""
When I run `rspec define_group_metadata_with_hash_spec.rb`
Then the examples should all pass
Scenario: define example metadata using a hash
Given a file named "define_example_metadata_with_hash_spec.rb" with:
"""ruby
describe "a group with no user-defined metadata" do
it 'has an example with metadata', :foo => 17 do
example.metadata[:foo].should eq(17)
example.metadata.should_not include(:bar)
end
it 'has another example with metadata', :bar => 12, :bazz => 33 do
example.metadata[:bar].should eq(12)
example.metadata[:bazz].should eq(33)
example.metadata.should_not include(:foo)
end
end
"""
When I run `rspec define_example_metadata_with_hash_spec.rb`
Then the examples should all pass
Scenario: override user-defined metadata
Given a file named "override_metadata_spec.rb" with:
"""ruby
describe "a group with user-defined metadata", :foo => 'bar' do
it 'can be overridden by an example', :foo => 'bazz' do
example.metadata[:foo].should == 'bazz'
end
describe "a sub-group with an override", :foo => 'goo' do
it 'can be overridden by a sub-group' do
example.metadata[:foo].should == 'goo'
end
end
end
"""
When I run `rspec override_metadata_spec.rb`
Then the examples should all pass
Scenario: less verbose metadata
Given a file named "less_verbose_metadata_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
end
describe "a group with simple metadata", :fast, :simple, :bug => 73 do
it 'has `:fast => true` metadata' do
example.metadata[:fast].should == true
end
it 'has `:simple => true` metadata' do
example.metadata[:simple].should == true
end
it 'can still use a hash for metadata' do
example.metadata[:bug].should eq(73)
end
it 'can define simple metadata on an example', :special do
example.metadata[:special].should == true
end
end
"""
When I run `rspec less_verbose_metadata_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/metadata/current_example.feature 0000644 0000041 0000041 00000001003 12261207027 024040 0 ustar www-data www-data Feature: current example
You can reference the example object, and access its metadata, using
the `example` method within an example.
Scenario: access the example object from within an example
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "an example" do
it "knows itself as example" do
example.description.should eq("knows itself as example")
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the example should pass
rspec-core-2.14.7/features/step_definitions/ 0000755 0000041 0000041 00000000000 12261207027 021062 5 ustar www-data www-data rspec-core-2.14.7/features/step_definitions/additional_cli_steps.rb 0000644 0000041 0000041 00000003177 12261207027 025574 0 ustar www-data www-data require 'rspec/core' # to fix annoying "undefined method `configuration' for RSpec:Module (NoMethodError)"
Then /^the output should contain all of these:$/ do |table|
table.raw.flatten.each do |string|
assert_partial_output(string, all_output)
end
end
Then /^the output should not contain any of these:$/ do |table|
table.raw.flatten.each do |string|
all_output.should_not =~ regexp(string)
end
end
Then /^the output should contain one of the following:$/ do |table|
matching_output = table.raw.flatten.select do |string|
all_output =~ regexp(string)
end
matching_output.should have(1).item
end
Then /^the example(?:s)? should(?: all)? pass$/ do
step %q{the output should contain "0 failures"}
step %q{the output should not contain "0 examples"}
step %q{the exit status should be 0}
end
Then /^the process should succeed even though no examples were run$/ do
step %q{the output should contain "0 examples, 0 failures"}
step %q{the exit status should be 0}
end
Then /^the backtrace\-normalized output should contain:$/ do |partial_output|
# ruby 1.9 includes additional stuff in the backtrace,
# so we need to normalize it to compare it with our expected output.
normalized_output = all_output.split("\n").map do |line|
line =~ /(^\s+# [^:]+:\d+)/ ? $1 : line # http://rubular.com/r/zDD7DdWyzF
end.join("\n")
normalized_output.should =~ regexp(partial_output)
end
# This step can be generalized if it's ever used to test other colors
Then /^the failing example is printed in magenta$/ do
# \e[35m = enable magenta
# \e[0m = reset colors
expect(all_output).to include("\e[35m" + "F" + "\e[0m")
end
rspec-core-2.14.7/features/subject/ 0000755 0000041 0000041 00000000000 12261207027 017153 5 ustar www-data www-data rspec-core-2.14.7/features/subject/attribute_of_subject.feature 0000644 0000041 0000041 00000006456 12261207027 024751 0 ustar www-data www-data Feature: attribute of subject
WARNING: `its` will be extracted from rspec-core-3.0 into its own gem.
Use the `its` method as a short-hand to generate a nested example group with
a single example that specifies the expected value of an attribute of the
subject. This can be used with an implicit or explicit subject.
`its` accepts a symbol or a string, and a block representing the example.
its(:size) { should eq(1) }
its("length") { should eq(1) }
You can use a string with dots to specify a nested attribute (i.e. an
attribute of the attribute of the subject).
its("phone_numbers.size") { should eq(2) }
When the subject is a hash, you can pass in an array with a single key to
access the value at that key in the hash.
its([:key]) { should eq(value) }
Scenario: specify value of an attribute
Given a file named "example_spec.rb" with:
"""ruby
describe Array do
context "when first created" do
its(:size) { should eq(0) }
end
end
"""
When I run `rspec example_spec.rb --format documentation`
Then the output should contain:
"""
Array
when first created
size
should eq 0
"""
Scenario: specify value of a nested attribute
Given a file named "example_spec.rb" with:
"""ruby
class Person
attr_reader :phone_numbers
def initialize
@phone_numbers = []
end
end
describe Person do
context "with one phone number (555-1212)"do
subject do
person = Person.new
person.phone_numbers << "555-1212"
person
end
its("phone_numbers.first") { should eq("555-1212") }
end
end
"""
When I run `rspec example_spec.rb --format documentation`
Then the output should contain:
"""
Person
with one phone number (555-1212)
phone_numbers.first
should eq "555-1212"
"""
Scenario: specify value of an attribute of a hash
Given a file named "example_spec.rb" with:
"""ruby
describe Hash do
context "with two items" do
subject do
{:one => 'one', :two => 'two'}
end
its(:size) { should eq(2) }
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
Scenario: specify value for key in a hash
Given a file named "example_spec.rb" with:
"""ruby
describe Hash do
context "with keys :one and 'two'" do
subject do
{:one => 1, "two" => 2}
end
its([:one]) { should eq(1) }
its(["two"]) { should eq(2) }
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
Scenario: specify value for key in a hash-like object
Given a file named "example_spec.rb" with:
"""ruby
require 'matrix'
describe Matrix do
context "with values [[1, 2], [3, 4]]" do
subject do
Matrix[[1, 2], [3, 4]]
end
its([0, 1]) { should eq(2) }
its([1, 0]) { should eq(3) }
its([1, 2]) { should be_nil }
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/subject/implicit_subject.feature 0000644 0000041 0000041 00000003652 12261207027 024067 0 ustar www-data www-data Feature: implicitly defined subject
If the first argument to the outermost example group is a class, an instance
of that class is exposed to each example via the `subject` method.
While the examples below demonstrate how `subject` can be used as a
user-facing concept, we recommend that you reserve it for support of custom
matchers and/or extension libraries that hide its use from examples.
Scenario: subject exposed in top level group
Given a file named "top_level_subject_spec.rb" with:
"""ruby
describe Array do
it "should be empty when first created" do
subject.should be_empty
end
end
"""
When I run `rspec ./top_level_subject_spec.rb`
Then the examples should all pass
Scenario: subject in a nested group
Given a file named "nested_subject_spec.rb" with:
"""ruby
describe Array do
describe "when first created" do
it "should be empty" do
subject.should be_empty
end
end
end
"""
When I run `rspec nested_subject_spec.rb`
Then the examples should all pass
Scenario: subject in a nested group with a different class (outermost wins)
Given a file named "nested_subject_spec.rb" with:
"""ruby
class ArrayWithOneElement < Array
def initialize(*)
super
unshift "first element"
end
end
describe Array do
describe ArrayWithOneElement do
context "referenced as subject" do
it "should be empty (because it is the Array declared at the top)" do
subject.should be_empty
end
end
context "created in the example" do
it "should not be empty" do
ArrayWithOneElement.new.should_not be_empty
end
end
end
end
"""
When I run `rspec nested_subject_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/subject/implicit_receiver.feature 0000644 0000041 0000041 00000001416 12261207027 024230 0 ustar www-data www-data Feature: implicit receiver
When `should` is called in an example without an explicit receiver, it is
invoked against the subject (explicit or implicit).
Scenario: implicit subject
Given a file named "example_spec.rb" with:
"""ruby
describe Array do
describe "when first created" do
it { should be_empty }
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
Scenario: explicit subject
Given a file named "example_spec.rb" with:
"""ruby
describe Array do
describe "with 3 items" do
subject { [1,2,3] }
it { should_not be_empty }
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/subject/explicit_subject.feature 0000644 0000041 0000041 00000006200 12261207027 024066 0 ustar www-data www-data Feature: explicit subject
Use `subject` in the group scope to explicitly define the value that is
returned by the `subject` method in the example scope.
Note that while the examples below demonstrate how `subject` can be used as a
user-facing concept, we recommend that you reserve it for support of custom
matchers and/or extension libraries that hide its use from examples.
Scenario: subject in top level group
Given a file named "top_level_subject_spec.rb" with:
"""ruby
describe Array, "with some elements" do
subject { [1,2,3] }
it "should have the prescribed elements" do
subject.should == [1,2,3]
end
end
"""
When I run `rspec top_level_subject_spec.rb`
Then the examples should all pass
Scenario: subject in a nested group
Given a file named "nested_subject_spec.rb" with:
"""ruby
describe Array do
subject { [1,2,3] }
describe "with some elements" do
it "should have the prescribed elements" do
subject.should == [1,2,3]
end
end
end
"""
When I run `rspec nested_subject_spec.rb`
Then the examples should all pass
Scenario: access subject from before block
Given a file named "top_level_subject_spec.rb" with:
"""ruby
describe Array, "with some elements" do
subject { [] }
before { subject.push(1,2,3) }
it "should have the prescribed elements" do
subject.should == [1,2,3]
end
end
"""
When I run `rspec top_level_subject_spec.rb`
Then the examples should all pass
Scenario: invoke helper method from subject block
Given a file named "helper_subject_spec.rb" with:
"""ruby
describe Array do
def prepared_array; [1,2,3] end
subject { prepared_array }
describe "with some elements" do
it "should have the prescribed elements" do
subject.should == [1,2,3]
end
end
end
"""
When I run `rspec helper_subject_spec.rb`
Then the examples should all pass
Scenario: subject block is invoked at most once per example
Given a file named "nil_subject_spec.rb" with:
"""ruby
describe Array do
describe "#[]" do
context "with index out of bounds" do
before { Array.should_receive(:one_two_three).once.and_return([1,2,3]) }
subject { Array.one_two_three[42] }
it { should be_nil }
end
end
end
"""
When I run `rspec nil_subject_spec.rb`
Then the examples should all pass
Scenario: subject bang method
Given a file named "subject_bang_spec.rb" with:
"""ruby
describe Array do
describe '#pop' do
let(:prepared_array) { [1,2,3] }
subject! { prepared_array.pop }
it "removes the last value from the array" do
prepared_array.should eq([1,2])
end
it "returns the last value of the array" do
subject.should eq(3)
end
end
end
"""
When I run `rspec subject_bang_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/pending/ 0000755 0000041 0000041 00000000000 12261207027 017140 5 ustar www-data www-data rspec-core-2.14.7/features/pending/pending_examples.feature 0000644 0000041 0000041 00000017345 12261207027 024051 0 ustar www-data www-data Feature: pending examples
RSpec offers four ways to indicate that an example is disabled pending
some action.
Scenario: pending implementation
Given a file named "example_without_block_spec.rb" with:
"""ruby
describe "an example" do
it "is a pending example"
end
"""
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 "example_without_block_spec.rb:2"
Scenario: pending any arbitrary reason, with no block
Given a file named "pending_without_block_spec.rb" with:
"""ruby
describe "an example" do
it "is implemented but waiting" do
pending("something else getting finished")
this_should_not_get_executed
end
end
"""
When I run `rspec pending_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:
"""
Pending:
an example is implemented but waiting
# something else getting finished
# ./pending_without_block_spec.rb:2
"""
Scenario: pending any arbitrary reason, with a block that fails
Given a file named "pending_with_failing_block_spec.rb" with:
"""ruby
describe "an example" do
it "is implemented but waiting" do
pending("something else getting finished") do
raise "this is the failure"
end
end
end
"""
When I run `rspec pending_with_failing_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:
"""
Pending:
an example is implemented but waiting
# something else getting finished
# ./pending_with_failing_block_spec.rb:2
"""
Scenario: pending any arbitrary reason, with a block that passes
Given a file named "pending_with_passing_block_spec.rb" with:
"""ruby
describe "an example" do
it "is implemented but waiting" do
pending("something else getting finished") do
true.should be(true)
end
end
end
"""
When I run `rspec pending_with_passing_block_spec.rb`
Then the exit status should not be 0
And the output should contain "1 example, 1 failure"
And the output should contain "FIXED"
And the output should contain "Expected pending 'something else getting finished' to fail. No Error was raised."
And the output should contain "pending_with_passing_block_spec.rb:3"
Scenario: temporarily pending by prefixing `it`, `specify`, or `example` with an x
Given a file named "temporarily_pending_spec.rb" with:
"""ruby
describe "an example" do
xit "is pending using xit" do
end
xspecify "is pending using xspecify" do
end
xexample "is pending using xexample" do
end
end
"""
When I run `rspec temporarily_pending_spec.rb`
Then the exit status should be 0
And the output should contain "3 examples, 0 failures, 3 pending"
And the output should contain:
"""
Pending:
an example is pending using xit
# Temporarily disabled with xit
# ./temporarily_pending_spec.rb:2
an example is pending using xspecify
# Temporarily disabled with xspecify
# ./temporarily_pending_spec.rb:5
an example is pending using xexample
# Temporarily disabled with xexample
# ./temporarily_pending_spec.rb:8
"""
Scenario: example with no docstring and pending method using documentation formatter
Given a file named "pending_with_no_docstring_spec.rb" with:
"""ruby
describe "an example" do
it "checks something" do
(3+4).should eq(7)
end
specify do
pending
end
end
"""
When I run `rspec pending_with_no_docstring_spec.rb --format documentation`
Then the exit status should be 0
And the output should contain "2 examples, 0 failures, 1 pending"
And the output should contain:
"""
an example
checks something
example at ./pending_with_no_docstring_spec.rb:5 (PENDING: No reason given)
"""
Scenario: pending with no docstring using documentation formatter
Given a file named "pending_with_no_docstring_spec.rb" with:
"""ruby
describe "an example" do
it "checks something" do
(3+4).should eq(7)
end
pending do
"string".reverse.should eq("gnirts")
end
end
"""
When I run `rspec pending_with_no_docstring_spec.rb --format documentation`
Then the exit status should be 0
And the output should contain "2 examples, 0 failures, 1 pending"
And the output should contain:
"""
an example
checks something
example at ./pending_with_no_docstring_spec.rb:5 (PENDING: No reason given)
"""
Scenario: conditionally pending examples
Given a file named "conditionally_pending_spec.rb" with:
"""ruby
describe "a failing spec" do
def run_test; raise "failure"; end
it "is pending when pending with a true :if condition" do
pending("true :if", :if => true) { run_test }
end
it "fails when pending with a false :if condition" do
pending("false :if", :if => false) { run_test }
end
it "is pending when pending with a false :unless condition" do
pending("false :unless", :unless => false) { run_test }
end
it "fails when pending with a true :unless condition" do
pending("true :unless", :unless => true) { run_test }
end
end
describe "a passing spec" do
def run_test; true.should be(true); end
it "fails when pending with a true :if condition" do
pending("true :if", :if => true) { run_test }
end
it "passes when pending with a false :if condition" do
pending("false :if", :if => false) { run_test }
end
it "fails when pending with a false :unless condition" do
pending("false :unless", :unless => false) { run_test }
end
it "passes when pending with a true :unless condition" do
pending("true :unless", :unless => true) { run_test }
end
end
"""
When I run `rspec ./conditionally_pending_spec.rb`
Then the output should contain "8 examples, 4 failures, 2 pending"
And the output should contain:
"""
Pending:
a failing spec is pending when pending with a true :if condition
# true :if
# ./conditionally_pending_spec.rb:4
a failing spec is pending when pending with a false :unless condition
# false :unless
# ./conditionally_pending_spec.rb:12
"""
And the output should contain:
"""
1) a failing spec fails when pending with a false :if condition
Failure/Error: def run_test; raise "failure"; end
"""
And the output should contain:
"""
2) a failing spec fails when pending with a true :unless condition
Failure/Error: def run_test; raise "failure"; end
"""
And the output should contain:
"""
3) a passing spec fails when pending with a true :if condition FIXED
Expected pending 'true :if' to fail. No Error was raised.
"""
And the output should contain:
"""
4) a passing spec fails when pending with a false :unless condition FIXED
Expected pending 'false :unless' to fail. No Error was raised.
"""
rspec-core-2.14.7/features/spec_files/ 0000755 0000041 0000041 00000000000 12261207027 017630 5 ustar www-data www-data rspec-core-2.14.7/features/spec_files/arbitrary_file_suffix.feature 0000644 0000041 0000041 00000000440 12261207027 025565 0 ustar www-data www-data Feature: arbitrary file suffix
Scenario: .spec
Given a file named "a.spec" with:
"""ruby
describe "something" do
it "does something" do
3.should eq(3)
end
end
"""
When I run `rspec a.spec`
Then the examples should all pass
rspec-core-2.14.7/features/helper_methods/ 0000755 0000041 0000041 00000000000 12261207027 020516 5 ustar www-data www-data rspec-core-2.14.7/features/helper_methods/let.feature 0000644 0000041 0000041 00000002640 12261207027 022661 0 ustar www-data www-data Feature: let and let!
Use `let` to define a memoized helper method. The value will be cached
across multiple calls in the same example but not across examples.
Note that `let` is lazy-evaluated: it is not evaluated until the first time
the method it defines is invoked. You can use `let!` to force the method's
invocation before each example.
Scenario: use let to define memoized helper method
Given a file named "let_spec.rb" with:
"""ruby
$count = 0
describe "let" do
let(:count) { $count += 1 }
it "memoizes the value" do
count.should eq(1)
count.should eq(1)
end
it "is not cached across examples" do
count.should eq(2)
end
end
"""
When I run `rspec let_spec.rb`
Then the examples should all pass
Scenario: use let! to define a memoized helper method that is called in a before hook
Given a file named "let_bang_spec.rb" with:
"""ruby
$count = 0
describe "let!" do
invocation_order = []
let!(:count) do
invocation_order << :let!
$count += 1
end
it "calls the helper method in a before hook" do
invocation_order << :example
invocation_order.should == [:let!, :example]
count.should eq(1)
end
end
"""
When I run `rspec let_bang_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/helper_methods/modules.feature 0000644 0000041 0000041 00000011714 12261207027 023547 0 ustar www-data www-data Feature: Define helper methods in a module
You can define helper methods in a module and include it in
your example groups using the `config.include` configuration
option. `config.extend` can be used to extend the module onto
your example groups so that the methods in the module are available
in the example groups themselves (but not in the actual examples).
You can also include or extend the module onto only certain example
groups by passing a metadata hash as the last argument. Only groups
that match the given metadata will include or extend the module.
If you set the `treat_symbols_as_metadata_keys_with_true_values` config option
to `true`, you can specify metadata using only symbols.
Background:
Given a file named "helpers.rb" with:
"""ruby
module Helpers
def help
:available
end
end
"""
Scenario: include a module in all example groups
Given a file named "include_module_spec.rb" with:
"""ruby
require './helpers'
RSpec.configure do |c|
c.include Helpers
end
describe "an example group" do
it "has access to the helper methods defined in the module" do
help.should be(:available)
end
end
"""
When I run `rspec include_module_spec.rb`
Then the examples should all pass
Scenario: extend a module in all example groups
Given a file named "extend_module_spec.rb" with:
"""ruby
require './helpers'
RSpec.configure do |c|
c.extend Helpers
end
describe "an example group" do
puts "Help is #{help}"
it "does not have access to the helper methods defined in the module" do
expect { help }.to raise_error(NameError)
end
end
"""
When I run `rspec extend_module_spec.rb`
Then the examples should all pass
And the output should contain "Help is available"
Scenario: include a module in only some example groups
Given a file named "include_module_in_some_groups_spec.rb" with:
"""ruby
require './helpers'
RSpec.configure do |c|
c.include Helpers, :foo => :bar
end
describe "an example group with matching metadata", :foo => :bar do
it "has access to the helper methods defined in the module" do
help.should be(:available)
end
end
describe "an example group without matching metadata" do
it "does not have access to the helper methods defined in the module" do
expect { help }.to raise_error(NameError)
end
end
"""
When I run `rspec include_module_in_some_groups_spec.rb`
Then the examples should all pass
Scenario: extend a module in only some example groups
Given a file named "extend_module_in_only_some_groups_spec.rb" with:
"""ruby
require './helpers'
RSpec.configure do |c|
c.extend Helpers, :foo => :bar
end
describe "an example group with matching metadata", :foo => :bar do
puts "In a matching group, help is #{help}"
it "does not have access to the helper methods defined in the module" do
expect { help }.to raise_error(NameError)
end
end
describe "an example group without matching metadata" do
puts "In a non-matching group, help is #{help rescue 'not available'}"
it "does not have access to the helper methods defined in the module" do
expect { help }.to raise_error(NameError)
end
end
"""
When I run `rspec extend_module_in_only_some_groups_spec.rb`
Then the examples should all pass
And the output should contain "In a matching group, help is available"
And the output should contain "In a non-matching group, help is not available"
Scenario: use symbols as metadata
Given a file named "symbols_as_metadata_spec.rb" with:
"""ruby
require './helpers'
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
c.include Helpers, :include_helpers
c.extend Helpers, :extend_helpers
end
describe "an example group with matching include metadata", :include_helpers do
puts "In a group not matching the extend filter, help is #{help rescue 'not available'}"
it "has access to the helper methods defined in the module" do
help.should be(:available)
end
end
describe "an example group with matching extend metadata", :extend_helpers do
puts "In a group matching the extend filter, help is #{help}"
it "does not have access to the helper methods defined in the module" do
expect { help }.to raise_error(NameError)
end
end
"""
When I run `rspec symbols_as_metadata_spec.rb`
Then the examples should all pass
And the output should contain "In a group not matching the extend filter, help is not available"
And the output should contain "In a group matching the extend filter, help is available"
rspec-core-2.14.7/features/helper_methods/arbitrary_methods.feature 0000644 0000041 0000041 00000002213 12261207027 025613 0 ustar www-data www-data Feature: arbitrary helper methods
You can define methods in any example group using Ruby's `def` keyword or
`define_method` method. These _helper_ methods are exposed to examples in the
group in which they are defined and groups nested within that group, but not
parent or sibling groups.
Scenario: use a method defined in the same group
Given a file named "example_spec.rb" with:
"""ruby
describe "an example" do
def help
:available
end
it "has access to methods defined in its group" do
help.should be(:available)
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
Scenario: use a method defined in a parent group
Given a file named "example_spec.rb" with:
"""ruby
describe "an example" do
def help
:available
end
describe "in a nested group" do
it "has access to methods defined in its parent group" do
help.should be(:available)
end
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/configuration/ 0000755 0000041 0000041 00000000000 12261207027 020363 5 ustar www-data www-data rspec-core-2.14.7/features/configuration/order_and_seed.feature 0000644 0000041 0000041 00000000416 12261207027 024676 0 ustar www-data www-data Feature: set the order and/or seed
You can set the order to run specs and specify a seed if you are running the specs using the 'random' ordering. See the documentation on the --order command line option for more on this.
rspec-core-2.14.7/features/configuration/alias_example_to.feature 0000644 0000041 0000041 00000002716 12261207027 025254 0 ustar www-data www-data Feature: alias_example_to
Use `config.alias_example_to` to create new example group methods
that define examples with the configured metadata.
If you set the `treat_symbols_as_metadata_keys_with_true_values` config option
to `true`, you can specify metadata using only symbols.
Scenario: Use alias_example_to to define focused example
Given a file named "alias_example_to_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.alias_example_to :fit, :focused => true
c.filter_run :focused => true
end
describe "an example group" do
it "does one thing" do
end
fit "does another thing" do
end
end
"""
When I run `rspec alias_example_to_spec.rb --format doc`
Then the output should contain "does another thing"
And the output should not contain "does one thing"
Scenario: use symbols as metadata
Given a file named "use_symbols_as_metadata_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
c.alias_example_to :fit, :focused
c.filter_run :focused
end
describe "an example group" do
it "does one thing" do
end
fit "does another thing" do
end
end
"""
When I run `rspec use_symbols_as_metadata_spec.rb --format doc`
Then the output should contain "does another thing"
And the output should not contain "does one thing"
rspec-core-2.14.7/features/configuration/read_options_from_file.feature 0000644 0000041 0000041 00000005701 12261207027 026453 0 ustar www-data www-data Feature: read command line configuration options from files
RSpec reads command line configuration options from files in two different
locations:
Local: `./.rspec-local` (i.e. in the project's root directory, can be gitignored)
Project: `./.rspec` (i.e. in the project's root directory, usually checked into the project)
Global: `~/.rspec` (i.e. in the user's home directory)
Configuration options are loaded from `~/.rspec`, `.rspec`,
`.rspec-local`, command line switches, and the `SPEC_OPTS` environment
variable (listed in lowest to highest precedence; for example, an option
in `~/.rspec` can be overridden by an option in `.rspec-local`).
Scenario: color set in .rspec
Given a file named ".rspec" with:
"""
--color
"""
And a file named "spec/example_spec.rb" with:
"""ruby
describe "color_enabled" do
context "when set with RSpec.configure" do
before do
# color is disabled for non-tty output, so stub the output stream
# to say it is tty, even though we're running this with cucumber
RSpec.configuration.output_stream.stub(:tty?) { true }
end
it "is true" do
RSpec.configuration.should be_color_enabled
end
end
end
"""
When I run `rspec ./spec/example_spec.rb`
Then the examples should all pass
Scenario: custom options file
Given a file named "my.options" with:
"""
--format documentation
"""
And a file named "spec/example_spec.rb" with:
"""ruby
describe "formatter set in custom options file" do
it "sets formatter" do
RSpec.configuration.formatters.first.
should be_a(RSpec::Core::Formatters::DocumentationFormatter)
end
end
"""
When I run `rspec spec/example_spec.rb --options my.options`
Then the examples should all pass
Scenario: RSpec ignores ./.rspec when custom options file is used
Given a file named "my.options" with:
"""
--format documentation
"""
And a file named ".rspec" with:
"""
--color
"""
And a file named "spec/example_spec.rb" with:
"""ruby
describe "custom options file" do
it "causes .rspec to be ignored" do
RSpec.configuration.color_enabled.should be_false
end
end
"""
When I run `rspec spec/example_spec.rb --options my.options`
Then the examples should all pass
Scenario: using ERB in .rspec
Given a file named ".rspec" with:
"""
--format <%= true ? 'documentation' : 'progress' %>
"""
And a file named "spec/example_spec.rb" with:
"""ruby
describe "formatter" do
it "is set to documentation" do
RSpec.configuration.formatters.first.should be_an(RSpec::Core::Formatters::DocumentationFormatter)
end
end
"""
When I run `rspec ./spec/example_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/configuration/custom_settings.feature 0000644 0000041 0000041 00000004654 12261207027 025203 0 ustar www-data www-data Feature: custom settings
Extensions like rspec-rails can add their own configuration settings.
Scenario: simple setting (with defaults)
Given a file named "additional_setting_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.add_setting :custom_setting
end
describe "custom setting" do
it "is nil by default" do
RSpec.configuration.custom_setting.should be_nil
end
it "acts false by default" do
RSpec.configuration.custom_setting.should be_false
end
it "is exposed as a predicate" do
RSpec.configuration.custom_setting?.should be_false
end
it "can be overridden" do
RSpec.configuration.custom_setting = true
RSpec.configuration.custom_setting.should be_true
RSpec.configuration.custom_setting?.should be_true
end
end
"""
When I run `rspec ./additional_setting_spec.rb`
Then the examples should all pass
Scenario: default to true
Given a file named "additional_setting_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.add_setting :custom_setting, :default => true
end
describe "custom setting" do
it "is true by default" do
RSpec.configuration.custom_setting.should be_true
end
it "is exposed as a predicate" do
RSpec.configuration.custom_setting?.should be_true
end
it "can be overridden" do
RSpec.configuration.custom_setting = false
RSpec.configuration.custom_setting.should be_false
RSpec.configuration.custom_setting?.should be_false
end
end
"""
When I run `rspec ./additional_setting_spec.rb`
Then the examples should all pass
Scenario: overridden in a subsequent RSpec.configure block
Given a file named "additional_setting_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.add_setting :custom_setting
end
RSpec.configure do |c|
c.custom_setting = true
end
describe "custom setting" do
it "returns the value set in the last cofigure block to get eval'd" do
RSpec.configuration.custom_setting.should be_true
end
it "is exposed as a predicate" do
RSpec.configuration.custom_setting?.should be_true
end
end
"""
When I run `rspec ./additional_setting_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/configuration/run_all_when_everything_filtered.feature 0000644 0000041 0000041 00000005034 12261207027 030541 0 ustar www-data www-data Feature: run all when everything filtered
Use the run_all_when_everything_filtered option to tell RSpec to run all the
specs in the case where you try to run a filtered list of specs but no specs
match that filter. This works well when paired with an inclusion filter like
`:focus => true`, as it will run all the examples when none match the
inclusion filter.
RSpec.configure { |c| c.run_all_when_everything_filtered = true }
Background:
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure {|c| c.run_all_when_everything_filtered = true}
"""
Scenario: by default, no specs are run if they are all filtered out by an inclusion tag
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "examples" do
it "with no tag" do
end
it "with no tag as well" do
end
end
"""
When I run `rspec spec/example_spec.rb --tag some_tag`
Then the output should contain "0 examples, 0 failures"
Scenario: specs are still run if they are filtered out by an exclusion tag
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "examples" do
it "with no tag" do
end
it "with no tag as well" do
end
end
"""
When I run `rspec spec/example_spec.rb --tag ~some_tag`
Then the output should contain "2 examples, 0 failures"
Scenario: when the run_all_when_everything_filtered option is turned on, if there are any matches for the filtering tag, only those features are run
Given a file named "spec/example_spec.rb" with:
"""ruby
require "spec_helper"
describe "examples" do
it "with no tag", :some_tag => true do
end
it "with no tag as well" do
end
end
"""
When I run `rspec spec/example_spec.rb --tag some_tag`
Then the output should contain "1 example, 0 failures"
And the output should contain "Run options: include {:some_tag=>true}"
Scenario: when the run_all_when_everything_filtered option is turned on, all the specs are run when the tag has no matches
Given a file named "spec/example_spec.rb" with:
"""ruby
require "spec_helper"
describe "examples" do
it "with no tag" do
end
it "with no tag as well" do
end
end
"""
When I run `rspec spec/example_spec.rb --tag some_tag`
Then the output should contain "2 examples, 0 failures"
And the output should contain "All examples were filtered out; ignoring {:some_tag=>true}"
rspec-core-2.14.7/features/configuration/show_failures_in_pending_blocks.feature 0000644 0000041 0000041 00000003657 12261207027 030354 0 ustar www-data www-data Feature: show_failures_in_pending_blocks
Use the show_failures_in_pending_blocks option to run the code in pending blocks while keeping the tests pending.
RSpec.configure { |c| c.show_failures_in_pending_blocks = true }
Background:
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure {|c| c.show_failures_in_pending_blocks = true}
"""
Scenario: by default, code in pending examples is not exercised
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "fails" do
pending "code will not be exercised" do
fail
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the output should not contain "Failure/Error: pending { fail }"
Scenario: by default, code in pending blocks inside examples is not exercised
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "fails" do
it "code will not be exercised" do
pending { fail }
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the output should not contain "Failure/Error: pending { fail }"
Scenario: when turned on, pending code blocks inside examples are exercised
Given a file named "spec/example_spec.rb" with:
"""ruby
require "spec_helper"
describe "fails" do
it "code will be exercised" do
pending { fail }
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the output should contain "Failure/Error: pending { fail }"
Scenario: when turned on, code inside pending examples is not exercised
Given a file named "spec/example_spec.rb" with:
"""ruby
require "spec_helper"
describe "fails" do
pending "code will not be exercised" do
fail
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the output should not contain "Failure/Error: pending { fail }"
rspec-core-2.14.7/features/configuration/deprecation_stream.feature 0000644 0000041 0000041 00000003600 12261207027 025607 0 ustar www-data www-data Feature: deprecation_stream
Define a custom output stream for warning about deprecations (default `$stderr`).
RSpec.configure {|c| c.deprecation_stream = File.open('deprecations.txt', 'w') }
or
RSpec.configure {|c| c.deprecation_stream = 'deprecations.txt' }
Background:
Given a file named "lib/foo.rb" with:
"""ruby
class Foo
def bar
RSpec.deprecate "Foo#bar"
end
end
"""
Scenario: default - print deprecations to $stderr
Given a file named "spec/example_spec.rb" with:
"""ruby
require "foo"
describe "calling a deprecated method" do
example { Foo.new.bar }
end
"""
When I run `rspec spec/example_spec.rb`
Then the output should contain "DEPRECATION: Foo#bar is deprecated"
Scenario: configure using the path to a file
Given a file named "spec/example_spec.rb" with:
"""ruby
require "foo"
RSpec.configure {|c| c.deprecation_stream = 'deprecations.txt' }
describe "calling a deprecated method" do
example { Foo.new.bar }
end
"""
When I run `rspec spec/example_spec.rb`
Then the output should not contain "DEPRECATION"
But the output should contain "1 deprecation logged to deprecations.txt"
And the file "deprecations.txt" should contain "Foo#bar is deprecated"
Scenario: configure using a File object
Given a file named "spec/example_spec.rb" with:
"""ruby
require "foo"
RSpec.configure {|c| c.deprecation_stream = File.open('deprecations.txt', 'w') }
describe "calling a deprecated method" do
example { Foo.new.bar }
end
"""
When I run `rspec spec/example_spec.rb`
Then the output should not contain "DEPRECATION"
But the output should contain "1 deprecation logged to deprecations.txt"
And the file "deprecations.txt" should contain "Foo#bar is deprecated"
rspec-core-2.14.7/features/configuration/default_path.feature 0000644 0000041 0000041 00000002314 12261207027 024400 0 ustar www-data www-data Feature: default_path
As of rspec-2.7, you can just type `rspec` to run all specs that live
in the `spec` directory.
This is supported by a `--default_path` option, which is set to `spec` by
default. If you prefer to keep your specs in a different directory, or assign
an individual file to `--default_path`, you can do so on the command line or
in a configuration file (`.rspec`, `~/.rspec`, or a custom file).
NOTE: this option is not supported on `RSpec.configuration`, as it needs to
be set before spec files are loaded.
Scenario: run `rspec` with default default_path (`spec` directory)
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "an example" do
it "passes" do
end
end
"""
When I run `rspec`
Then the output should contain "1 example, 0 failures"
Scenario: run `rspec` with customized default_path
Given a file named ".rspec" with:
"""
--default_path behavior
"""
Given a file named "behavior/example_spec.rb" with:
"""ruby
describe "an example" do
it "passes" do
end
end
"""
When I run `rspec`
Then the output should contain "1 example, 0 failures"
rspec-core-2.14.7/features/configuration/output_stream.feature 0000644 0000041 0000041 00000001267 12261207027 024661 0 ustar www-data www-data Feature: output_stream
Define a custom output stream (default `$stdout`). Aliases: `:output`, `:out`.
RSpec.configure { |c| c.output_stream = File.open('saved_output', 'w') }
Background:
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure {|c| c.output_stream = File.open('saved_output', 'w') }
"""
Scenario: redirecting output
Given a file named "spec/example_spec.rb" with:
"""ruby
require 'spec_helper'
describe "an example" do
it "passes" do
true
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the file "saved_output" should contain "1 example, 0 failures"
rspec-core-2.14.7/features/configuration/profile.feature 0000644 0000041 0000041 00000016774 12261207027 023417 0 ustar www-data www-data Feature: Profile examples
The `--profile` command line option (available from `RSpec.configure` as
`#profile_examples`), when set, will cause RSpec to dump out a list of
your slowest examples. By default, it prints the 10 slowest examples,
but you can set it to a different value to have it print more or fewer
slow examples. If `--fail-fast` option is used together with `--profile`
and there is a failure, slow examples are not shown.
Background:
Given a file named "spec/spec_helper.rb" with:
"""ruby
"""
And a file named "spec/example_spec.rb" with:
"""ruby
require "spec_helper"
describe "something" do
it "sleeps for 0.1 seconds (example 1)" do
sleep 0.1
1.should == 1
end
it "sleeps for 0 seconds (example 2)" do
2.should == 2
end
it "sleeps for 0.15 seconds (example 3)" do
sleep 0.15
3.should == 3
end
it "sleeps for 0.05 seconds (example 4)" do
sleep 0.05
4.should == 4
end
it "sleeps for 0.05 seconds (example 5)" do
sleep 0.05
5.should == 5
end
it "sleeps for 0.05 seconds (example 6)" do
sleep 0.05
6.should == 6
end
it "sleeps for 0.05 seconds (example 7)" do
sleep 0.05
7.should == 7
end
it "sleeps for 0.05 seconds (example 8)" do
sleep 0.05
8.should == 8
end
it "sleeps for 0.05 seconds (example 9)" do
sleep 0.05
9.should == 9
end
it "sleeps for 0.05 seconds (example 10)" do
sleep 0.05
10.should == 10
end
it "sleeps for 0.05 seconds (example 11)" do
sleep 0.05
11.should == 11
end
end
"""
Scenario: by default does not show profile
When I run `rspec spec`
Then the examples should all pass
And the output should not contain "example 1"
And the output should not contain "example 2"
And the output should not contain "example 3"
And the output should not contain "example 4"
And the output should not contain "example 5"
And the output should not contain "example 6"
And the output should not contain "example 7"
And the output should not contain "example 8"
And the output should not contain "example 9"
And the output should not contain "example 10"
And the output should not contain "example 11"
Scenario: setting `profile_examples` to true shows 10 examples
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure { |c| c.profile_examples = true }
"""
When I run `rspec spec`
Then the examples should all pass
And the output should contain "Top 10 slowest examples"
And the output should contain "example 1"
And the output should not contain "example 2"
And the output should contain "example 3"
And the output should contain "example 4"
And the output should contain "example 5"
And the output should contain "example 6"
And the output should contain "example 7"
And the output should contain "example 8"
And the output should contain "example 9"
And the output should contain "example 10"
And the output should contain "example 11"
Scenario: setting `profile_examples` to 2 shows 2 examples
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure { |c| c.profile_examples = 2 }
"""
When I run `rspec spec`
Then the examples should all pass
And the output should contain "Top 2 slowest examples"
And the output should contain "example 1"
And the output should not contain "example 2"
And the output should contain "example 3"
And the output should not contain "example 4"
And the output should not contain "example 5"
And the output should not contain "example 6"
And the output should not contain "example 7"
And the output should not contain "example 8"
And the output should not contain "example 9"
And the output should not contain "example 10"
And the output should not contain "example 11"
Scenario: setting profile examples through CLI
When I run `rspec spec --profile 2`
Then the examples should all pass
And the output should contain "Top 2 slowest examples"
And the output should contain "example 1"
And the output should not contain "example 2"
And the output should contain "example 3"
And the output should not contain "example 4"
And the output should not contain "example 5"
And the output should not contain "example 6"
And the output should not contain "example 7"
And the output should not contain "example 8"
And the output should not contain "example 9"
And the output should not contain "example 10"
And the output should not contain "example 11"
Scenario: Using `--no-profile` overrules config options
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure { |c| c.profile_examples = true }
"""
When I run `rspec spec --no-profile`
Then the examples should all pass
And the output should not contain "example 1"
And the output should not contain "example 2"
And the output should not contain "example 3"
And the output should not contain "example 4"
And the output should not contain "example 5"
And the output should not contain "example 6"
And the output should not contain "example 7"
And the output should not contain "example 8"
And the output should not contain "example 9"
And the output should not contain "example 10"
And the output should not contain "example 11"
Scenario: Using `--profile` with `--fail-fast` shows slow examples if everything passes
When I run `rspec spec --fail-fast --profile`
Then the examples should all pass
And the output should contain "Top 10 slowest examples"
And the output should contain "example 1"
And the output should not contain "example 2"
And the output should contain "example 3"
And the output should contain "example 4"
And the output should contain "example 5"
And the output should contain "example 6"
And the output should contain "example 7"
And the output should contain "example 8"
And the output should contain "example 9"
And the output should contain "example 10"
And the output should contain "example 11"
Scenario: Using `--profile` shows slow examples even in case of failures
Given a file named "spec/example_spec.rb" with:
"""ruby
require "spec_helper"
describe "something" do
it "sleeps for 0.1 seconds (example 1)" do
sleep 0.1
1.should == 1
end
it "fails" do
fail
end
end
"""
When I run `rspec spec --profile`
Then the output should contain "2 examples, 1 failure"
And the output should contain "Top 2 slowest examples"
And the output should contain "example 1"
Scenario: Using `--profile` with `--fail-fast` doesn't show slow examples in case of failures
Given a file named "spec/example_spec.rb" with:
"""ruby
require "spec_helper"
describe "something" do
it "sleeps for 0.1 seconds (example 1)" do
sleep 0.1
1.should == 1
end
it "fails" do
fail
end
end
"""
When I run `rspec spec --fail-fast --profile`
Then the output should not contain "Top 2 slowest examples"
And the output should not contain "example 1"
rspec-core-2.14.7/features/configuration/fail_fast.feature 0000644 0000041 0000041 00000003430 12261207027 023670 0 ustar www-data www-data Feature: fail fast
Use the fail_fast option to tell RSpec to abort the run on first failure:
RSpec.configure {|c| c.fail_fast = true}
Background:
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure {|c| c.fail_fast = true}
"""
Scenario: fail_fast with no failures (runs all examples)
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "something" do
it "passes" do
end
it "passes too" do
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the examples should all pass
Scenario: fail_fast with first example failing (only runs the one example)
Given a file named "spec/example_spec.rb" with:
"""ruby
require "spec_helper"
describe "something" do
it "fails" do
fail
end
it "passes" do
end
end
"""
When I run `rspec spec/example_spec.rb -fd`
Then the output should contain "1 example, 1 failure"
Scenario: fail_fast with multiple files, second example failing (only runs the first two examples)
Given a file named "spec/example_1_spec.rb" with:
"""ruby
require "spec_helper"
describe "something" do
it "passes" do
end
it "fails" do
fail
end
end
describe "something else" do
it "fails" do
fail
end
end
"""
And a file named "spec/example_2_spec.rb" with:
"""ruby
require "spec_helper"
describe "something" do
it "passes" do
end
end
describe "something else" do
it "fails" do
fail
end
end
"""
When I run `rspec spec`
Then the output should contain "2 examples, 1 failure"
rspec-core-2.14.7/features/configuration/backtrace_clean_patterns.feature 0000644 0000041 0000041 00000005303 12261207027 026742 0 ustar www-data www-data Feature: Backtrace cleaning
To aid in diagnozing spec failures, RSpec cleans matching lines from backtraces. The default patterns cleaned are:
/\/lib\d*\/ruby\//,
/org\/jruby\//,
/bin\//,
/gems/,
/spec\/spec_helper\.rb/,
/lib\/rspec\/(core|expectations|matchers|mocks)/
This list can be modified or replaced with the `backtrace_clean_patterns` option. Additionally, rspec can be run with the `--backtrace` option to skip backtrace cleaning entirely.
Scenario: default configuration
Given a file named "spec/failing_spec.rb" with:
"""ruby
describe "2 + 2" do
it "is 5" do
(2+2).should eq(5)
end
end
"""
When I run `rspec`
Then the output should contain "1 example, 1 failure"
And the output should not contain "lib/rspec/expectations"
Scenario: With a custom setting for backtrace_clean_patterns
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure do |config|
config.backtrace_clean_patterns = [
/spec_helper/
]
end
def foo
"bar"
end
"""
And a file named "spec/example_spec.rb" with:
"""ruby
require 'spec_helper'
describe "foo" do
it "returns baz" do
foo.should eq("baz")
end
end
"""
When I run `rspec`
Then the output should contain "1 example, 1 failure"
And the output should contain "lib/rspec/expectations"
Scenario: Adding a pattern
Given a file named "spec/matchers/be_baz_matcher.rb" with:
"""ruby
RSpec::Matchers.define :be_baz do |_|
match do |actual|
actual == "baz"
end
end
"""
And a file named "spec/example_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.backtrace_clean_patterns << /be_baz_matcher/
end
describe "bar" do
it "is baz" do
"bar".should be_baz
end
end
"""
When I run `rspec`
Then the output should contain "1 example, 1 failure"
But the output should not contain "be_baz_matcher"
And the output should not contain "lib/rspec/expectations"
Scenario: Running with the --backtrace option
Given a file named "spec/matchers/be_baz_matcher.rb" with:
"""ruby
RSpec::Matchers.define :be_baz do |_|
match do |actual|
actual == "baz"
end
end
"""
And a file named "spec/example_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.backtrace_clean_patterns << /be_baz_matcher/
end
describe "bar" do
it "is baz" do
"bar".should be_baz
end
end
"""
When I run `rspec --backtrace`
Then the output should contain "1 example, 1 failure"
And the output should not contain "be_baz_matcher"
rspec-core-2.14.7/features/configuration/failure_exit_code.feature 0000644 0000041 0000041 00000001646 12261207027 025421 0 ustar www-data www-data Feature: failure exit code
Use the feature_exit_code option to set a custom exit code when RSpec fails.
RSpec.configure { |c| c.failure_exit_code = 42 }
Background:
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure { |c| c.failure_exit_code = 42 }
"""
Scenario: a failing spec with the default exit code
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "something" do
it "fails" do
fail
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the exit status should be 1
Scenario: a failing spec with a custom exit code
Given a file named "spec/example_spec.rb" with:
"""ruby
require 'spec_helper'
describe "something" do
it "fails" do
fail
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the exit status should be 42
rspec-core-2.14.7/features/configuration/pattern.feature 0000644 0000041 0000041 00000002322 12261207027 023414 0 ustar www-data www-data Feature: pattern
Use the pattern option to tell RSpec to look for specs in files that match a pattern other than "**/*_spec.rb".
Background:
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "two specs here" do
it "passes" do
end
it "passes too" do
end
end
"""
And a file named "spec/example_test.rb" with:
"""ruby
describe "only one spec" do
it "passes" do
end
end
"""
Scenario: by default, RSpec runs files that match "**/*_spec.rb"
When I run `rspec`
Then the output should contain "2 examples, 0 failures"
Scenario: the --pattern flag makes RSpec run files matching the specified pattern and ignore the default pattern
When I run `rspec -P "**/*_test.rb"`
Then the output should contain "1 example, 0 failures"
Scenario: the --pattern flag can be used to pass in multiple patterns, separated by comma
When I run `rspec -P "**/*_test.rb,**/*_spec.rb"`
Then the output should contain "3 examples, 0 failures"
Scenario: the --pattern flag accepts shell style glob unions
When I run `rspec -P "**/*_{test,spec}.rb"`
Then the output should contain "3 examples, 0 failures"
rspec-core-2.14.7/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature 0000644 0000041 0000041 00000003204 12261207027 033655 0 ustar www-data www-data Feature: treat symbols as metadata keys with true values
Use the treat_symbols_as_metadata_keys_with_true_values option to tell RSpec that :key is shorthand for :key => true.
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = true }
Background:
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = true }
"""
Scenario: by default, symbols without values are ignored and the specs are filtered out
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "failed filtering" do
it "this will be filted out", :some_tag do
true
end
it "so will this" do
false
end
end
"""
When I run `rspec spec/example_spec.rb --tag some_tag`
Then the output should contain "0 examples, 0 failures"
And the output should contain "All examples were filtered out"
Scenario: when treat_symbols_as_metadata_keys_with_true_values is true, specs can be tagged with only a symbol
Given a file named "spec/example_spec.rb" with:
"""ruby
require "spec_helper"
describe "run me", :some_tag do
it "runs" do
true
end
end
describe "run one of these" do
it "run this one", :some_tag do
true
end
it "but not me" do
false
end
end
"""
When I run `rspec spec/example_spec.rb --tag some_tag`
Then the output should contain "2 examples, 0 failures"
And the output should contain "Run options: include {:some_tag=>true}"
rspec-core-2.14.7/features/hooks/ 0000755 0000041 0000041 00000000000 12261207027 016637 5 ustar www-data www-data rspec-core-2.14.7/features/hooks/filtering.feature 0000644 0000041 0000041 00000015611 12261207027 022203 0 ustar www-data www-data Feature: filters
`before`, `after`, and `around` hooks defined in the block passed to
`RSpec.configure` can be constrained to specific examples and/or groups using
metadata as a filter.
RSpec.configure do |c|
c.before(:each, :type => :model) do
end
end
describe "something", :type => :model do
end
You can specify metadata using only symbols if you set the
`treat_symbols_as_metadata_keys_with_true_values` config option to `true`.
Scenario: filter `before(:each)` hooks using arbitrary metadata
Given a file named "filter_before_each_hooks_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.before(:each, :foo => :bar) do
invoked_hooks << :before_each_foo_bar
end
end
describe "a filtered before :each hook" do
let(:invoked_hooks) { [] }
describe "group without matching metadata" do
it "does not run the hook" do
invoked_hooks.should be_empty
end
it "runs the hook for an example with matching metadata", :foo => :bar do
invoked_hooks.should == [:before_each_foo_bar]
end
end
describe "group with matching metadata", :foo => :bar do
it "runs the hook" do
invoked_hooks.should == [:before_each_foo_bar]
end
end
end
"""
When I run `rspec filter_before_each_hooks_spec.rb`
Then the examples should all pass
Scenario: filter `after(:each)` hooks using arbitrary metadata
Given a file named "filter_after_each_hooks_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.after(:each, :foo => :bar) do
raise "boom!"
end
end
describe "a filtered after :each hook" do
describe "group without matching metadata" do
it "does not run the hook" do
# should pass
end
it "runs the hook for an example with matching metadata", :foo => :bar do
# should fail
end
end
describe "group with matching metadata", :foo => :bar do
it "runs the hook" do
# should fail
end
end
end
"""
When I run `rspec filter_after_each_hooks_spec.rb`
Then the output should contain "3 examples, 2 failures"
Scenario: filter around(:each) hooks using arbitrary metadata
Given a file named "filter_around_each_hooks_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.around(:each, :foo => :bar) do |example|
order << :before_around_each_foo_bar
example.run
order.should == [:before_around_each_foo_bar, :example]
end
end
describe "a filtered around(:each) hook" do
let(:order) { [] }
describe "a group without matching metadata" do
it "does not run the hook" do
order.should be_empty
end
it "runs the hook for an example with matching metadata", :foo => :bar do
order.should == [:before_around_each_foo_bar]
order << :example
end
end
describe "a group with matching metadata", :foo => :bar do
it "runs the hook for an example with matching metadata", :foo => :bar do
order.should == [:before_around_each_foo_bar]
order << :example
end
end
end
"""
When I run `rspec filter_around_each_hooks_spec.rb`
Then the examples should all pass
Scenario: filter before(:all) hooks using arbitrary metadata
Given a file named "filter_before_all_hooks_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.before(:all, :foo => :bar) { @hook = :before_all_foo_bar }
end
describe "a filtered before(:all) hook" do
describe "a group without matching metadata" do
it "does not run the hook" do
@hook.should be_nil
end
describe "a nested subgroup with matching metadata", :foo => :bar do
it "runs the hook" do
@hook.should == :before_all_foo_bar
end
end
end
describe "a group with matching metadata", :foo => :bar do
it "runs the hook" do
@hook.should == :before_all_foo_bar
end
describe "a nested subgroup" do
it "runs the hook" do
@hook.should == :before_all_foo_bar
end
end
end
end
"""
When I run `rspec filter_before_all_hooks_spec.rb`
Then the examples should all pass
Scenario: filter after(:all) hooks using arbitrary metadata
Given a file named "filter_after_all_hooks_spec.rb" with:
"""ruby
example_msgs = []
RSpec.configure do |config|
config.after(:all, :foo => :bar) do
puts "after :all"
end
end
describe "a filtered after(:all) hook" do
describe "a group without matching metadata" do
it "does not run the hook" do
puts "unfiltered"
end
end
describe "a group with matching metadata", :foo => :bar do
it "runs the hook" do
puts "filtered 1"
end
end
describe "another group without matching metadata" do
describe "a nested subgroup with matching metadata", :foo => :bar do
it "runs the hook" do
puts "filtered 2"
end
end
end
end
"""
When I run `rspec --format progress filter_after_all_hooks_spec.rb`
Then the examples should all pass
And the output should contain:
"""
unfiltered
.filtered 1
.after :all
filtered 2
.after :all
"""
Scenario: Use symbols as metadata
Given a file named "less_verbose_metadata_filter.rb" with:
"""ruby
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
c.before(:each, :before_each) { puts "before each" }
c.after(:each, :after_each) { puts "after each" }
c.around(:each, :around_each) do |example|
puts "around each (before)"
example.run
puts "around each (after)"
end
c.before(:all, :before_all) { puts "before all" }
c.after(:all, :after_all) { puts "after all" }
end
describe "group 1", :before_all, :after_all do
it("") { puts "example 1" }
it("", :before_each) { puts "example 2" }
it("", :after_each) { puts "example 3" }
it("", :around_each) { puts "example 4" }
end
"""
When I run `rspec --format progress less_verbose_metadata_filter.rb`
Then the examples should all pass
And the output should contain:
"""
before all
example 1
.before each
example 2
.example 3
after each
.around each (before)
example 4
around each (after)
.after all
"""
rspec-core-2.14.7/features/hooks/before_and_after_hooks.feature 0000644 0000041 0000041 00000024664 12261207027 024700 0 ustar www-data www-data Feature: before and after hooks
Use `before` and `after` hooks to execute arbitrary code before and/or
after the body of an example is run:
before(:each) # run before each example
before(:all) # run one time only, before all of the examples in a group
after(:each) # run after each example
after(:all) # run one time only, after all of the examples in a group
Before and after blocks are called in the following order:
before suite
before all
before each
after each
after all
after suite
`before` and `after` hooks can be defined directly in the example groups they
should run in, or in a global RSpec.configure block.
Setting instance variables are not supported in `before(:suite)`.
Mocks are only supported in `before(:each)`.
Scenario: define before(:each) block
Given a file named "before_each_spec.rb" with:
"""ruby
require "rspec/expectations"
class Thing
def widgets
@widgets ||= []
end
end
describe Thing do
before(:each) do
@thing = Thing.new
end
describe "initialized in before(:each)" do
it "has 0 widgets" do
@thing.should have(0).widgets
end
it "can get accept new widgets" do
@thing.widgets << Object.new
end
it "does not share state across examples" do
@thing.should have(0).widgets
end
end
end
"""
When I run `rspec before_each_spec.rb`
Then the examples should all pass
Scenario: define before(:all) block in example group
Given a file named "before_all_spec.rb" with:
"""ruby
require "rspec/expectations"
class Thing
def widgets
@widgets ||= []
end
end
describe Thing do
before(:all) do
@thing = Thing.new
end
describe "initialized in before(:all)" do
it "has 0 widgets" do
@thing.should have(0).widgets
end
it "can get accept new widgets" do
@thing.widgets << Object.new
end
it "shares state across examples" do
@thing.should have(1).widgets
end
end
end
"""
When I run `rspec before_all_spec.rb`
Then the examples should all pass
When I run `rspec before_all_spec.rb:15`
Then the examples should all pass
Scenario: failure in before(:all) block
Given a file named "before_all_spec.rb" with:
"""ruby
describe "an error in before(:all)" do
before(:all) do
raise "oops"
end
it "fails this example" do
end
it "fails this example, too" do
end
after(:all) do
puts "after all ran"
end
describe "nested group" do
it "fails this third example" do
end
it "fails this fourth example" do
end
describe "yet another level deep" do
it "fails this last example" do
end
end
end
end
"""
When I run `rspec before_all_spec.rb --format documentation`
Then the output should contain "5 examples, 5 failures"
And the output should contain:
"""
an error in before(:all)
fails this example (FAILED - 1)
fails this example, too (FAILED - 2)
nested group
fails this third example (FAILED - 3)
fails this fourth example (FAILED - 4)
yet another level deep
fails this last example (FAILED - 5)
after all ran
"""
When I run `rspec before_all_spec.rb:9 --format documentation`
Then the output should contain "1 example, 1 failure"
And the output should contain:
"""
an error in before(:all)
fails this example, too (FAILED - 1)
"""
Scenario: failure in after(:all) block
Given a file named "after_all_spec.rb" with:
"""ruby
describe "an error in after(:all)" do
after(:all) do
raise StandardError.new("Boom!")
end
it "passes this example" do
end
it "passes this example, too" do
end
end
"""
When I run `rspec after_all_spec.rb`
Then the examples should all pass
And the output should contain:
"""
An error occurred in an after(:all) hook.
StandardError: Boom!
"""
Scenario: define before and after blocks in configuration
Given a file named "befores_in_configuration_spec.rb" with:
"""ruby
require "rspec/expectations"
RSpec.configure do |config|
config.before(:each) do
@before_each = "before each"
end
config.before(:all) do
@before_all = "before all"
end
end
describe "stuff in before blocks" do
describe "with :all" do
it "should be available in the example" do
@before_all.should eq("before all")
end
end
describe "with :each" do
it "should be available in the example" do
@before_each.should eq("before each")
end
end
end
"""
When I run `rspec befores_in_configuration_spec.rb`
Then the examples should all pass
Scenario: before/after blocks are run in order
Given a file named "ensure_block_order_spec.rb" with:
"""ruby
require "rspec/expectations"
describe "before and after callbacks" do
before(:all) do
puts "before all"
end
before(:each) do
puts "before each"
end
after(:each) do
puts "after each"
end
after(:all) do
puts "after all"
end
it "gets run in order" do
end
end
"""
When I run `rspec --format progress ensure_block_order_spec.rb`
Then the output should contain:
"""
before all
before each
after each
.after all
"""
Scenario: before/after blocks defined in config are run in order
Given a file named "configuration_spec.rb" with:
"""ruby
require "rspec/expectations"
RSpec.configure do |config|
config.before(:suite) do
puts "before suite"
end
config.before(:all) do
puts "before all"
end
config.before(:each) do
puts "before each"
end
config.after(:each) do
puts "after each"
end
config.after(:all) do
puts "after all"
end
config.after(:suite) do
puts "after suite"
end
end
describe "ignore" do
example "ignore" do
end
end
"""
When I run `rspec --format progress configuration_spec.rb`
Then the output should contain:
"""
before suite
before all
before each
after each
.after all
after suite
"""
Scenario: before/after all blocks are run once
Given a file named "before_and_after_all_spec.rb" with:
"""ruby
describe "before and after callbacks" do
before(:all) do
puts "outer before all"
end
example "in outer group" do
end
after(:all) do
puts "outer after all"
end
describe "nested group" do
before(:all) do
puts "inner before all"
end
example "in nested group" do
end
after(:all) do
puts "inner after all"
end
end
end
"""
When I run `rspec --format progress before_and_after_all_spec.rb`
Then the examples should all pass
And the output should contain:
"""
outer before all
.inner before all
.inner after all
outer after all
"""
When I run `rspec --format progress before_and_after_all_spec.rb:14`
Then the examples should all pass
And the output should contain:
"""
outer before all
inner before all
.inner after all
outer after all
"""
When I run `rspec --format progress before_and_after_all_spec.rb:6`
Then the examples should all pass
And the output should contain:
"""
outer before all
.outer after all
"""
Scenario: nested examples have access to state set in outer before(:all)
Given a file named "before_all_spec.rb" with:
"""ruby
describe "something" do
before :all do
@value = 123
end
describe "nested" do
it "access state set in before(:all)" do
@value.should eq(123)
end
describe "nested more deeply" do
it "access state set in before(:all)" do
@value.should eq(123)
end
end
end
describe "nested in parallel" do
it "access state set in before(:all)" do
@value.should eq(123)
end
end
end
"""
When I run `rspec before_all_spec.rb`
Then the examples should all pass
Scenario: before/after all blocks have access to state
Given a file named "before_and_after_all_spec.rb" with:
"""ruby
describe "before and after callbacks" do
before(:all) do
@outer_state = "set in outer before all"
end
example "in outer group" do
@outer_state.should eq("set in outer before all")
end
describe "nested group" do
before(:all) do
@inner_state = "set in inner before all"
end
example "in nested group" do
@outer_state.should eq("set in outer before all")
@inner_state.should eq("set in inner before all")
end
after(:all) do
@inner_state.should eq("set in inner before all")
end
end
after(:all) do
@outer_state.should eq("set in outer before all")
end
end
"""
When I run `rspec before_and_after_all_spec.rb`
Then the examples should all pass
Scenario: exception in before(:each) is captured and reported as failure
Given a file named "error_in_before_each_spec.rb" with:
"""ruby
describe "error in before(:each)" do
before(:each) do
raise "this error"
end
it "is reported as failure" do
end
end
"""
When I run `rspec error_in_before_each_spec.rb`
Then the output should contain "1 example, 1 failure"
And the output should contain "this error"
rspec-core-2.14.7/features/hooks/around_hooks.feature 0000644 0000041 0000041 00000022251 12261207027 022711 0 ustar www-data www-data Feature: around hooks
Around hooks receive the example as a block argument, extended to behave like
a proc. This lets you define code that should be executed before and after
the example. Of course, you can do the same thing with before and after hooks,
and it's often cleaner to do so.
Where around hooks shine is when you want to run an example in a block. For
example, if your database library offers a transaction method that receives
a block, you can use an around hook as described in the first scenario:
WARNING: around hooks do not share state with the example the way before and
after hooks do. This means that you can not share instance variables between
around hooks and examples.
Also, mock frameworks are set up and torn down within the context of running
the example, so you can not interact with them directly in around hooks.
Scenario: use the example as a proc within the block passed to around()
Given a file named "example_spec.rb" with:
"""ruby
class Database
def self.transaction
puts "open transaction"
yield
puts "close transaction"
end
end
describe "around filter" do
around(:each) do |example|
Database.transaction(&example)
end
it "gets run in order" do
puts "run the example"
end
end
"""
When I run `rspec example_spec.rb`
Then the output should contain:
"""
open transaction
run the example
close transaction
"""
Scenario: invoke the example using run()
Given a file named "example_spec.rb" with:
"""ruby
describe "around hook" do
around(:each) do |example|
puts "around each before"
example.run
puts "around each after"
end
it "gets run in order" do
puts "in the example"
end
end
"""
When I run `rspec example_spec.rb`
Then the output should contain:
"""
around each before
in the example
around each after
"""
Scenario: access the example metadata
Given a file named "example_spec.rb" with:
"""ruby
describe "something" do
around(:each) do |example|
puts example.metadata[:foo]
example.run
end
it "does something", :foo => "this should show up in the output" do
end
end
"""
When I run `rspec example_spec.rb`
Then the output should contain "this should show up in the output"
Scenario: define a global around hook
Given a file named "example_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.around(:each) do |example|
puts "around each before"
example.run
puts "around each after"
end
end
describe "around filter" do
it "gets run in order" do
puts "in the example"
end
end
"""
When I run `rspec example_spec.rb`
Then the output should contain:
"""
around each before
in the example
around each after
"""
Scenario: before/after(:each) hooks are wrapped by the around hook
Given a file named "example_spec.rb" with:
"""ruby
describe "around filter" do
around(:each) do |example|
puts "around each before"
example.run
puts "around each after"
end
before(:each) do
puts "before each"
end
after(:each) do
puts "after each"
end
it "gets run in order" do
puts "in the example"
end
end
"""
When I run `rspec example_spec.rb`
Then the output should contain:
"""
around each before
before each
in the example
after each
around each after
"""
Scenario: before/after(:all) hooks are NOT wrapped by the around hook
Given a file named "example_spec.rb" with:
"""ruby
describe "around filter" do
around(:each) do |example|
puts "around each before"
example.run
puts "around each after"
end
before(:all) do
puts "before all"
end
after(:all) do
puts "after all"
end
it "gets run in order" do
puts "in the example"
end
end
"""
When I run `rspec --format progress example_spec.rb`
Then the output should contain:
"""
before all
around each before
in the example
around each after
.after all
"""
Scenario: examples run by an around block are run in the configured context
Given a file named "example_spec.rb" with:
"""ruby
module IncludedInConfigureBlock
def included_in_configure_block; true; end
end
RSpec.configure do |c|
c.include IncludedInConfigureBlock
end
describe "around filter" do
around(:each) do |example|
example.run
end
it "runs the example in the correct context" do
included_in_configure_block.should be_true
end
end
"""
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
Given a file named "example_spec.rb" with:
"""ruby
describe "implicit pending example" do
around(:each) do |example|
example.run
end
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
"""
Scenario: explicitly pending examples are detected as pending
Given a file named "example_spec.rb" with:
"""ruby
describe "explicit pending example" do
around(:each) do |example|
example.run
end
it "should be detected as pending" do
pending
end
end
"""
When I run `rspec example_spec.rb`
Then the output should contain "1 example, 0 failures, 1 pending"
And the output should contain:
"""
explicit pending example should be detected as pending
# No reason given
"""
Scenario: multiple around hooks in the same scope
Given a file named "example_spec.rb" with:
"""ruby
describe "if there are multiple around hooks in the same scope" do
around(:each) do |example|
puts "first around hook before"
example.run
puts "first around hook after"
end
around(:each) do |example|
puts "second around hook before"
example.run
puts "second around hook after"
end
it "they should all be run" do
puts "in the example"
1.should eq(1)
end
end
"""
When I run `rspec example_spec.rb`
Then the output should contain "1 example, 0 failure"
And the output should contain:
"""
first around hook before
second around hook before
in the example
second around hook after
first around hook after
"""
Scenario: around hooks in multiple scopes
Given a file named "example_spec.rb" with:
"""ruby
describe "if there are around hooks in an outer scope" do
around(:each) do |example|
puts "first outermost around hook before"
example.run
puts "first outermost around hook after"
end
around(:each) do |example|
puts "second outermost around hook before"
example.run
puts "second outermost around hook after"
end
describe "outer scope" do
around(:each) do |example|
puts "first outer around hook before"
example.run
puts "first outer around hook after"
end
around(:each) do |example|
puts "second outer around hook before"
example.run
puts "second outer around hook after"
end
describe "inner scope" do
around(:each) do |example|
puts "first inner around hook before"
example.run
puts "first inner around hook after"
end
around(:each) do |example|
puts "second inner around hook before"
example.run
puts "second inner around hook after"
end
it "they should all be run" do
puts "in the example"
end
end
end
end
"""
When I run `rspec example_spec.rb`
Then the output should contain "1 example, 0 failure"
And the output should contain:
"""
first outermost around hook before
second outermost around hook before
first outer around hook before
second outer around hook before
first inner around hook before
second inner around hook before
in the example
second inner around hook after
first inner around hook after
second outer around hook after
first outer around hook after
second outermost around hook after
first outermost around hook after
"""
rspec-core-2.14.7/features/filtering/ 0000755 0000041 0000041 00000000000 12261207027 017477 5 ustar www-data www-data rspec-core-2.14.7/features/filtering/inclusion_filters.feature 0000644 0000041 0000041 00000006170 12261207027 024613 0 ustar www-data www-data Feature: inclusion filters
You can constrain which examples are run by declaring an inclusion filter. The
most common use case is to focus on a subset of examples as you're focused on
a particular problem.
You can specify metadata using only symbols if you set the
`treat_symbols_as_metadata_keys_with_true_values` config option to `true`.
Background:
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure do |c|
c.filter_run_including :focus => true
end
"""
Scenario: focus on an example
Given a file named "spec/sample_spec.rb" with:
"""ruby
require "spec_helper"
describe "something" do
it "does one thing" do
end
it "does another thing", :focus => true do
end
end
"""
When I run `rspec spec/sample_spec.rb --format doc`
Then the output should contain "does another thing"
And the output should not contain "does one thing"
Scenario: focus on a group
Given a file named "spec/sample_spec.rb" with:
"""ruby
require "spec_helper"
describe "group 1", :focus => true do
it "group 1 example 1" do
end
it "group 1 example 2" do
end
end
describe "group 2" do
it "group 2 example 1" do
end
end
"""
When I run `rspec spec/sample_spec.rb --format doc`
Then the output should contain "group 1 example 1"
And the output should contain "group 1 example 2"
And the output should not contain "group 2 example 1"
Scenario: before/after(:all) hooks in unmatched example group are not run
Given a file named "spec/before_after_all_inclusion_filter_spec.rb" with:
"""ruby
require "spec_helper"
describe "group 1", :focus => true do
before(:all) { puts "before all in focused group" }
after(:all) { puts "after all in focused group" }
it "group 1 example" do
end
end
describe "group 2" do
before(:all) { puts "before all in unfocused group" }
after(:all) { puts "after all in unfocused group" }
context "context 1" do
it "group 2 context 1 example 1" do
end
end
end
"""
When I run `rspec ./spec/before_after_all_inclusion_filter_spec.rb`
Then the output should contain "before all in focused group"
And the output should contain "after all in focused group"
And the output should not contain "before all in unfocused group"
And the output should not contain "after all in unfocused group"
Scenario: Use symbols as metadata
Given a file named "symbols_as_metadata_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
c.filter_run :current_example
end
describe "something" do
it "does one thing" do
end
it "does another thing", :current_example do
end
end
"""
When I run `rspec symbols_as_metadata_spec.rb --format doc`
Then the output should contain "does another thing"
And the output should not contain "does one thing"
rspec-core-2.14.7/features/filtering/if_and_unless.feature 0000644 0000041 0000041 00000016011 12261207027 023664 0 ustar www-data www-data Feature: :if and :unless
The `:if` and `:unless` metadata keys can be used to filter examples without
needing to configure an exclusion filter.
Scenario: implicit :if filter
Given a file named "implicit_if_filter_spec.rb" with:
"""ruby
describe ":if => true group", :if => true do
it(":if => true group :if => true example", :if => true) { }
it(":if => true group :if => false example", :if => false) { }
it(":if => true group no :if example") { }
end
describe ":if => false group", :if => false do
it(":if => false group :if => true example", :if => true) { }
it(":if => false group :if => false example", :if => false) { }
it(":if => false group no :if example") { }
end
describe "no :if group" do
it("no :if group :if => true example", :if => true) { }
it("no :if group :if => false example", :if => false) { }
it("no :if group no :if example") { }
end
"""
When I run `rspec implicit_if_filter_spec.rb --format doc`
Then the output should contain all of these:
| :if => true group :if => true example |
| :if => true group no :if example |
| :if => false group :if => true example |
| no :if group :if => true example |
| no :if group no :if example |
And the output should not contain any of these:
| :if => true group :if => false example |
| :if => false group :if => false example |
| :if => false group no :if example |
| no :if group :if => false example |
Scenario: implicit :unless filter
Given a file named "implicit_unless_filter_spec.rb" with:
"""ruby
describe ":unless => true group", :unless => true do
it(":unless => true group :unless => true example", :unless => true) { }
it(":unless => true group :unless => false example", :unless => false) { }
it(":unless => true group no :unless example") { }
end
describe ":unless => false group", :unless => false do
it(":unless => false group :unless => true example", :unless => true) { }
it(":unless => false group :unless => false example", :unless => false) { }
it(":unless => false group no :unless example") { }
end
describe "no :unless group" do
it("no :unless group :unless => true example", :unless => true) { }
it("no :unless group :unless => false example", :unless => false) { }
it("no :unless group no :unless example") { }
end
"""
When I run `rspec implicit_unless_filter_spec.rb --format doc`
Then the output should contain all of these:
| :unless => true group :unless => false example |
| :unless => false group :unless => false example |
| :unless => false group no :unless example |
| no :unless group :unless => false example |
| no :unless group no :unless example |
And the output should not contain any of these:
| :unless => true group :unless => true example |
| :unless => true group no :unless example |
| :unless => false group :unless => true example |
| no :unless group :unless => true example |
Scenario: combining implicit filter with explicit inclusion filter
Given a file named "explicit_inclusion_filter_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.filter_run :focus => true
end
describe "group with :focus", :focus => true do
it("focused example") { }
it("focused :if => true example", :if => true) { }
it("focused :if => false example", :if => false) { }
it("focused :unless => true example", :unless => true) { }
it("focused :unless => false example", :unless => false) { }
end
describe "group without :focus" do
it("unfocused example") { }
it("unfocused :if => true example", :if => true) { }
it("unfocused :if => false example", :if => false) { }
it("unfocused :unless => true example", :unless => true) { }
it("unfocused :unless => false example", :unless => false) { }
end
"""
When I run `rspec explicit_inclusion_filter_spec.rb --format doc`
Then the output should contain all of these:
| focused example |
| focused :if => true example |
| focused :unless => false example |
And the output should not contain any of these:
| focused :if => false example |
| focused :unless => true example |
| unfocused |
Scenario: combining implicit filter with explicit exclusion filter
Given a file named "explicit_exclusion_filter_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.filter_run_excluding :broken => true
end
describe "unbroken group" do
it("included example") { }
it("included :if => true example", :if => true) { }
it("included :if => false example", :if => false) { }
it("included :unless => true example", :unless => true) { }
it("included :unless => false example", :unless => false) { }
end
describe "broken group", :broken => true do
it("excluded example") { }
it("excluded :if => true example", :if => true) { }
it("excluded :if => false example", :if => false) { }
it("excluded :unless => true example", :unless => true) { }
it("excluded :unless => false example", :unless => false) { }
end
"""
When I run `rspec explicit_exclusion_filter_spec.rb --format doc`
Then the output should contain all of these:
| included example |
| included :if => true example |
| included :unless => false example |
And the output should not contain any of these:
| included :if => false example |
| included :unless => true example |
| excluded |
Scenario: override implicit :if and :unless exclusion filters
Given a file named "override_implicit_filters_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.filter_run_excluding :if => :exclude_me, :unless => :exclude_me_for_unless
end
describe ":if filtering" do
it(":if => true example", :if => true) { }
it(":if => false example", :if => false) { }
it(":if => :exclude_me example", :if => :exclude_me) { }
end
describe ":unless filtering" do
it(":unless => true example", :unless => true) { }
it(":unless => false example", :unless => false) { }
it(":unless => :exclude_me_for_unless example", :unless => :exclude_me_for_unless) { }
end
"""
When I run `rspec override_implicit_filters_spec.rb --format doc`
Then the output should contain all of these:
| :if => true example |
| :if => false example |
| :unless => true example |
| :unless => false example |
And the output should not contain any of these:
| :if => :exclude_me example |
| :unless => :exclude_me_for_unless example |
rspec-core-2.14.7/features/filtering/exclusion_filters.feature 0000644 0000041 0000041 00000010030 12261207027 024607 0 ustar www-data www-data Feature: exclusion filters
You can exclude examples from a run by declaring an exclusion filter and
then tagging examples, or entire groups, with that filter.
If you set the `treat_symbols_as_metadata_keys_with_true_values` config option
to `true`, you can specify metadata using only symbols.
Scenario: exclude an example
Given a file named "spec/sample_spec.rb" with:
"""ruby
RSpec.configure do |c|
# declare an exclusion filter
c.filter_run_excluding :broken => true
end
describe "something" do
it "does one thing" do
end
# tag example for exclusion by adding metadata
it "does another thing", :broken => true do
end
end
"""
When I run `rspec ./spec/sample_spec.rb --format doc`
Then the output should contain "does one thing"
And the output should not contain "does another thing"
Scenario: exclude a group
Given a file named "spec/sample_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.filter_run_excluding :broken => true
end
describe "group 1", :broken => true do
it "group 1 example 1" do
end
it "group 1 example 2" do
end
end
describe "group 2" do
it "group 2 example 1" do
end
end
"""
When I run `rspec ./spec/sample_spec.rb --format doc`
Then the output should contain "group 2 example 1"
And the output should not contain "group 1 example 1"
And the output should not contain "group 1 example 2"
Scenario: exclude multiple groups
Given a file named "spec/sample_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.filter_run_excluding :broken => true
end
describe "group 1", :broken => true do
before(:all) do
raise "you should not see me"
end
it "group 1 example 1" do
end
it "group 1 example 2" do
end
end
describe "group 2", :broken => true do
before(:each) do
raise "you should not see me"
end
it "group 2 example 1" do
end
end
"""
When I run `rspec ./spec/sample_spec.rb --format doc`
Then the process should succeed even though no examples were run
And the output should not contain "group 1"
And the output should not contain "group 2"
Scenario: before/after(:all) hooks in excluded example group are not run
Given a file named "spec/before_after_all_exclusion_filter_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.filter_run_excluding :broken => true
end
describe "group 1" do
before(:all) { puts "before all in included group" }
after(:all) { puts "after all in included group" }
it "group 1 example" do
end
end
describe "group 2", :broken => true do
before(:all) { puts "before all in excluded group" }
after(:all) { puts "after all in excluded group" }
context "context 1" do
it "group 2 context 1 example 1" do
end
end
end
"""
When I run `rspec ./spec/before_after_all_exclusion_filter_spec.rb`
Then the output should contain "before all in included group"
And the output should contain "after all in included group"
And the output should not contain "before all in excluded group"
And the output should not contain "after all in excluded group"
Scenario: Use symbols as metadata
Given a file named "symbols_as_metadata_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
c.filter_run_excluding :broken
end
describe "something" do
it "does one thing" do
end
# tag example for exclusion by adding metadata
it "does another thing", :broken do
end
end
"""
When I run `rspec symbols_as_metadata_spec.rb --format doc`
Then the output should contain "does one thing"
And the output should not contain "does another thing"
rspec-core-2.14.7/features/example_groups/ 0000755 0000041 0000041 00000000000 12261207027 020546 5 ustar www-data www-data rspec-core-2.14.7/features/example_groups/shared_context.feature 0000644 0000041 0000041 00000004503 12261207027 025137 0 ustar www-data www-data Feature: shared context
Use `shared_context` to define a block that will be evaluated in the context
of example groups either explicitly, using `include_context`, or implicitly by
matching metadata.
Background:
Given a file named "shared_stuff.rb" with:
"""ruby
shared_context "shared stuff", :a => :b do
before { @some_var = :some_value }
def shared_method
"it works"
end
let(:shared_let) { {'arbitrary' => 'object'} }
subject do
'this is the subject'
end
end
"""
Scenario: declare shared context and include it with include_context
Given a file named "shared_context_example.rb" with:
"""ruby
require "./shared_stuff.rb"
describe "group that includes a shared context using 'include_context'" do
include_context "shared stuff"
it "has access to methods defined in shared context" do
shared_method.should eq("it works")
end
it "has access to methods defined with let in shared context" do
shared_let['arbitrary'].should eq('object')
end
it "runs the before hooks defined in the shared context" do
@some_var.should be(:some_value)
end
it "accesses the subject defined in the shared context" do
subject.should eq('this is the subject')
end
end
"""
When I run `rspec shared_context_example.rb`
Then the examples should all pass
Scenario: declare shared context and include it with metadata
Given a file named "shared_context_example.rb" with:
"""ruby
require "./shared_stuff.rb"
describe "group that includes a shared context using metadata", :a => :b do
it "has access to methods defined in shared context" do
shared_method.should eq("it works")
end
it "has access to methods defined with let in shared context" do
shared_let['arbitrary'].should eq('object')
end
it "runs the before hooks defined in the shared context" do
@some_var.should be(:some_value)
end
it "accesses the subject defined in the shared context" do
subject.should eq('this is the subject')
end
end
"""
When I run `rspec shared_context_example.rb`
Then the examples should all pass
rspec-core-2.14.7/features/example_groups/shared_examples.feature 0000644 0000041 0000041 00000021535 12261207027 025275 0 ustar www-data www-data Feature: shared examples
Shared examples let you describe behaviour of types or modules. When
declared, a shared group's content is stored. It is only realized in the
context of another example group, which provides any context the shared group
needs to run.
A shared group is included in another group using any of:
include_examples "name" # include the examples in the current context
it_behaves_like "name" # include the examples in a nested context
it_should_behave_like "name" # include the examples in a nested context
matching metadata # include the examples in the current context
WARNING: Files containing shared groups must be loaded before the files that
use them. While there are conventions to handle this, RSpec does _not_ do
anything special (like autoload). Doing so would require a strict naming
convention for files that would break existing suites.
CONVENTIONS:
1. The simplest approach is to require files with shared examples explicitly
from the files that use them. Keep in mind that RSpec adds the `spec`
directory to the `LOAD_PATH`, so you can say `require
'shared_examples_for_widgets'` to require a file at
`#{PROJECT_ROOT}/spec/shared_examples_for_widgets.rb`.
2. Put files containing shared examples in `spec/support/` and require files
in that directory from `spec/spec_helper.rb`:
Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
This is included in the generated `spec/spec_helper.rb` file in
`rspec-rails`
3. When all of the groups that include the shared group, just declare
the shared group in the same file.
Scenario: shared examples group included in two groups in one file
Given a file named "collection_spec.rb" with:
"""ruby
require "set"
shared_examples "a collection" do
let(:collection) { described_class.new([7, 2, 4]) }
context "initialized with 3 items" do
it "says it has three items" do
collection.size.should eq(3)
end
end
describe "#include?" do
context "with an an item that is in the collection" do
it "returns true" do
collection.include?(7).should be_true
end
end
context "with an an item that is not in the collection" do
it "returns false" do
collection.include?(9).should be_false
end
end
end
end
describe Array do
it_behaves_like "a collection"
end
describe Set do
it_behaves_like "a collection"
end
"""
When I run `rspec collection_spec.rb --format documentation`
Then the examples should all pass
And the output should contain:
"""
Array
behaves like a collection
initialized with 3 items
says it has three items
#include?
with an an item that is in the collection
returns true
with an an item that is not in the collection
returns false
Set
behaves like a collection
initialized with 3 items
says it has three items
#include?
with an an item that is in the collection
returns true
with an an item that is not in the collection
returns false
"""
Scenario: Providing context to a shared group using a block
Given a file named "shared_example_group_spec.rb" with:
"""ruby
require "set"
shared_examples "a collection object" do
describe "<<" do
it "adds objects to the end of the collection" do
collection << 1
collection << 2
expect(collection.to_a).to match_array([1, 2])
end
end
end
describe Array do
it_behaves_like "a collection object" do
let(:collection) { Array.new }
end
end
describe Set do
it_behaves_like "a collection object" do
let(:collection) { Set.new }
end
end
"""
When I run `rspec shared_example_group_spec.rb --format documentation`
Then the examples should all pass
And the output should contain:
"""
Array
behaves like a collection object
<<
adds objects to the end of the collection
Set
behaves like a collection object
<<
adds objects to the end of the collection
"""
Scenario: Passing parameters to a shared example group
Given a file named "shared_example_group_params_spec.rb" with:
"""ruby
shared_examples "a measurable object" do |measurement, measurement_methods|
measurement_methods.each do |measurement_method|
it "should return #{measurement} from ##{measurement_method}" do
subject.send(measurement_method).should == measurement
end
end
end
describe Array, "with 3 items" do
subject { [1, 2, 3] }
it_should_behave_like "a measurable object", 3, [:size, :length]
end
describe String, "of 6 characters" do
subject { "FooBar" }
it_should_behave_like "a measurable object", 6, [:size, :length]
end
"""
When I run `rspec shared_example_group_params_spec.rb --format documentation`
Then the examples should all pass
And the output should contain:
"""
Array with 3 items
it should behave like a measurable object
should return 3 from #size
should return 3 from #length
String of 6 characters
it should behave like a measurable object
should return 6 from #size
should return 6 from #length
"""
Scenario: Aliasing "it_should_behave_like" to "it_has_behavior"
Given a file named "shared_example_group_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
end
shared_examples 'sortability' do
it 'responds to <=>' do
sortable.should respond_to(:<=>)
end
end
describe String do
it_has_behavior 'sortability' do
let(:sortable) { 'sample string' }
end
end
"""
When I run `rspec shared_example_group_spec.rb --format documentation`
Then the examples should all pass
And the output should contain:
"""
String
has behavior: sortability
responds to <=>
"""
Scenario: Sharing metadata automatically includes shared example groups
Given a file named "shared_example_metadata_spec.rb" with:
"""ruby
shared_examples "shared stuff", :a => :b do
it 'runs wherever the metadata is shared' do
end
end
describe String, :a => :b do
end
"""
When I run `rspec shared_example_metadata_spec.rb`
Then the output should contain:
"""
1 example, 0 failures
"""
Scenario: Shared examples are nestable by context
Given a file named "context_specific_examples_spec.rb" with:
"""Ruby
describe "shared examples" do
context "per context" do
shared_examples "shared examples are nestable" do
specify { expect(true).to eq true }
end
it_behaves_like "shared examples are nestable"
end
end
"""
When I run `rspec context_specific_examples_spec.rb`
Then the output should contain:
"""
1 example, 0 failures
"""
Scenario: Shared examples are accessible from offspring contexts
Given a file named "context_specific_examples_spec.rb" with:
"""Ruby
describe "shared examples" do
shared_examples "shared examples are nestable" do
specify { expect(true).to eq true }
end
context "per context" do
it_behaves_like "shared examples are nestable"
end
end
"""
When I run `rspec context_specific_examples_spec.rb`
Then the output should contain:
"""
1 example, 0 failures
"""
And the output should not contain:
"""
Accessing shared_examples defined across contexts is deprecated
"""
Scenario: Shared examples are isolated per context
Given a file named "isolated_shared_examples_spec.rb" with:
"""Ruby
describe "shared examples" do
context do
shared_examples "shared examples are isolated" do
specify { expect(true).to eq true }
end
end
context do
it_behaves_like "shared examples are isolated"
end
end
"""
When I run `rspec isolated_shared_examples_spec.rb`
Then the output should contain:
"""
1 example, 0 failures
"""
But the output should contain:
"""
Accessing shared_examples defined across contexts is deprecated
"""
And the output should contain:
"""
isolated_shared_examples_spec.rb:9
"""
rspec-core-2.14.7/features/example_groups/basic_structure.feature 0000644 0000041 0000041 00000003174 12261207027 025331 0 ustar www-data www-data Feature: basic structure (describe/it)
RSpec is a DSL for creating executable examples of how code is expected to
behave, organized in groups. It uses the words "describe" and "it" so we can
express concepts like a conversation:
"Describe an account when it is first opened."
"It has a balance of zero."
The `describe` method creates an example group. Within the block passed to
`describe` you can declare nested groups using the `describe` or `context`
methods, or you can declare examples using the `it` or `specify` methods.
Under the hood, an example group is a class in which the block passed to
`describe` or `context` is evaluated. The blocks passed to `it` are evaluated
in the context of an _instance_ of that class.
Scenario: one group, one example
Given a file named "sample_spec.rb" with:
"""ruby
describe "something" do
it "does something" do
end
end
"""
When I run `rspec sample_spec.rb -fn`
Then the output should contain:
"""
something
does something
"""
Scenario: nested example groups (using context)
Given a file named "nested_example_groups_spec.rb" with:
"""ruby
describe "something" do
context "in one context" do
it "does one thing" do
end
end
context "in another context" do
it "does another thing" do
end
end
end
"""
When I run `rspec nested_example_groups_spec.rb -fdoc`
Then the output should contain:
"""
something
in one context
does one thing
in another context
does another thing
"""
rspec-core-2.14.7/features/Autotest.md 0000644 0000041 0000041 00000002731 12261207027 017651 0 ustar www-data www-data RSpec ships with a specialized subclass of Autotest. To use it, just add a
`.rspec` file to your project's root directory, and run the `autotest` command
as normal:
$ autotest
## Bundler
The `autotest` command generates a shell command that runs your specs. If you
are using Bundler, and you want the shell command to include `bundle exec`,
require the Autotest bundler plugin in a `.autotest` file in the project's root
directory or your home directory:
# in .autotest
require "autotest/bundler"
## Upgrading from previous versions of rspec
Previous versions of RSpec used a different mechanism for telling autotest to
invoke RSpec's Autotest extension: it generated an `autotest/discover.rb` file
in the project's root directory. This is no longer necessary with the new
approach of RSpec looking for a `.rspec` file, so feel free to delete the
`autotest/discover.rb` file in the project root if you have one.
## Gotchas
### Invalid Option: --tty
The `--tty` option was [added in rspec-core-2.2.1](changelog), and is used
internally by RSpec. If you see an error citing it as an invalid option, you'll
probably see there are two or more versions of rspec-core in the backtrace: one
< 2.2.1 and one >= 2.2.1.
This usually happens because you have a newer rspec-core installed, and an
older rspec-core specified in a Bundler Gemfile. If this is the case, you can:
1. specify the newer version in the Gemfile (recommended)
2. prefix the `autotest` command with `bundle exec`
rspec-core-2.14.7/features/mock_framework_integration/ 0000755 0000041 0000041 00000000000 12261207027 023125 5 ustar www-data www-data rspec-core-2.14.7/features/mock_framework_integration/use_mocha.feature 0000644 0000041 0000041 00000005421 12261207027 026447 0 ustar www-data www-data Feature: mock with mocha
Configure RSpec to use mocha as shown in the scenarios below.
Scenario: passing message expectation
Given a file named "example_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.mock_framework = :mocha
end
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:
"""ruby
RSpec.configure do |config|
config.mock_framework = :mocha
end
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:
"""ruby
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 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:
"""ruby
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:
"""ruby
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
rspec-core-2.14.7/features/mock_framework_integration/use_rr.feature 0000644 0000041 0000041 00000005273 12261207027 026010 0 ustar www-data www-data Feature: mock with rr
Configure RSpec to use rr as shown in the scenarios below.
Scenario: passing message expectation
Given a file named "example_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.mock_framework = :rr
end
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:
"""ruby
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:
"""ruby
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:
"""ruby
RSpec.configure do |config|
config.mock_framework = :rr
end
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 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:
"""ruby
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
rspec-core-2.14.7/features/mock_framework_integration/use_any_framework.feature 0000644 0000041 0000041 00000005442 12261207027 030227 0 ustar www-data www-data Feature: mock with an alternative framework
In addition to rspec, mocha, flexmock, and RR, you can choose an alternate
framework as the mocking framework. You (or the framework authors) just needs
to provide an adapter that hooks RSpec's events into those of the framework.
A mock framework adapter must expose three methods:
* `setup_mocks_for_rspec`
* called before each example is run
* `verify_mocks_for_rspec`
* called after each example is run
* this is where message expectation failures should result in an error with
the appropriate failure message
* `teardown_mocks_for_rspec`
* called after `verify_mocks_for_rspec`
* use this to clean up resources, restore objects to earlier state, etc
* guaranteed to run even if there are failures
Scenario: Mock with alternate framework
Given a file named "expector.rb" with:
"""ruby
class Expector
class << self
def expectors
@expectors ||= []
end
def clear_expectors
expectors.clear
end
def verify_expectors
expectors.each {|d| d.verify}
end
end
def initialize
self.class.expectors << self
end
def expectations
@expectations ||= []
end
def expect(message)
expectations << message.to_s
end
def verify
unless expectations.empty?
raise expectations.map {|e|
"expected #{e}, but it was never received"
}.join("\n")
end
end
private
def method_missing(name, *args, &block)
expectations.delete(name.to_s)
end
public
module RSpecAdapter
def setup_mocks_for_rspec
# no setup necessary
end
def verify_mocks_for_rspec
Expector.verify_expectors.each {|d| d.verify}
end
def teardown_mocks_for_rspec
Expector.clear_expectors
end
end
end
"""
Given a file named "example_spec.rb" with:
"""ruby
require File.expand_path("../expector", __FILE__)
RSpec.configure do |config|
config.mock_framework = Expector::RSpecAdapter
end
describe Expector do
it "passes when message is received" do
expector = Expector.new
expector.expect(:foo)
expector.foo
end
it "fails when message is received" do
expector = Expector.new
expector.expect(:foo)
end
end
"""
When I run `rspec example_spec.rb --format doc`
Then the exit status should be 1
And the output should contain "2 examples, 1 failure"
And the output should contain "fails when message is received (FAILED - 1)"
rspec-core-2.14.7/features/mock_framework_integration/use_rspec.feature 0000644 0000041 0000041 00000005471 12261207027 026501 0 ustar www-data www-data Feature: mock with rspec
RSpec uses its own mocking framework by default, or you can configure it
explicitly.
Scenario: passing message expectation
Given a file named "example_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.mock_framework = :rspec
end
describe "mocking with RSpec" do
it "passes when it should" do
receiver = double('receiver')
receiver.should_receive(: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:
"""ruby
RSpec.configure do |config|
config.mock_framework = :rspec
end
describe "mocking with RSpec" do
it "fails when it should" do
receiver = double('receiver')
receiver.should_receive(: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:
"""ruby
RSpec.configure do |config|
config.mock_framework = :rspec
end
describe "failed message expectation in a pending block" do
it "is listed as pending" do
pending do
receiver = double('receiver')
receiver.should_receive(: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:
"""ruby
RSpec.configure do |config|
config.mock_framework = :rspec
end
describe "passing message expectation in a pending block" do
it "fails with FIXED" do
pending do
receiver = double('receiver')
receiver.should_receive(:message)
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:
"""ruby
RSpec.configure do |config|
config.mock_framework = :rspec
end
describe "RSpec.configuration.mock_framework.framework_name" do
it "returns :rspec" do
RSpec.configuration.mock_framework.framework_name.should eq(:rspec)
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/mock_framework_integration/use_flexmock.feature 0000644 0000041 0000041 00000005535 12261207027 027176 0 ustar www-data www-data Feature: mock with flexmock
Configure RSpec to use flexmock as shown in the scenarios below.
Scenario: passing message expectation
Given a file named "example_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.mock_framework = :flexmock
end
describe "mocking with Flexmock" 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:
"""ruby
RSpec.configure do |config|
config.mock_framework = :flexmock
end
describe "mocking with Flexmock" 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:
"""ruby
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:
"""ruby
RSpec.configure do |config|
config.mock_framework = :flexmock
end
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 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:
"""ruby
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
rspec-core-2.14.7/features/formatters/ 0000755 0000041 0000041 00000000000 12261207027 017702 5 ustar www-data www-data rspec-core-2.14.7/features/formatters/custom_formatter.feature 0000644 0000041 0000041 00000002345 12261207027 024660 0 ustar www-data www-data Feature: custom formatters
RSpec ships with general purpose output formatters. You can tell RSpec which
one to use using the [`--format` command line
option]('../command_line/format_option').
When RSpec's built-in output formatters don't, however, give you everything
you need, you can write your own custom formatter and tell RSpec to use that
one instead. The simplest way is to subclass RSpec's `BaseTextFormatter`,
and then override just the methods that you want to modify.
Scenario: custom formatter
Given a file named "custom_formatter.rb" with:
"""ruby
require "rspec/core/formatters/base_text_formatter"
class CustomFormatter < RSpec::Core::Formatters::BaseTextFormatter
def initialize(output)
super(output)
end
def example_started(proxy)
output << "example: " << proxy.description
end
end
"""
And a file named "example_spec.rb" with:
"""ruby
describe "my group" do
specify "my example" do
end
end
"""
When I run `rspec example_spec.rb --require ./custom_formatter.rb --format CustomFormatter`
Then the output should contain "example: my example"
And the exit status should be 0
rspec-core-2.14.7/features/formatters/json_formatter.feature 0000644 0000041 0000041 00000002012 12261207027 024306 0 ustar www-data www-data Feature: JSON formatter
Scenario: Formatting example names for retry
Given a file named "various_spec.rb" with:
"""ruby
describe "Various" do
it "fails" do
"fail".should eq("succeed")
end
it "succeeds" do
"succeed".should eq("succeed")
end
it "pends"
end
"""
When I run `rspec various_spec.rb --format j`
Then the output should contain all of these:
|"summary_line":"3 examples, 1 failure, 1 pending"|
|"examples":[ |
|"description":"fails" |
|"full_description":"Various fails" |
|"status":"failed" |
|"file_path":"./various_spec.rb" |
|"line_number":2 |
|"exception":{ |
|"class":"RSpec::Expectations::ExpectationNotMetError"|
And the exit status should be 1
rspec-core-2.14.7/features/formatters/text_formatter.feature 0000644 0000041 0000041 00000002412 12261207027 024325 0 ustar www-data www-data Feature: text formatter
In order to easily see the result of running my specs
As an RSpec user
I want clear, concise, well-formatted output
Scenario: Backtrace formatting for failing specs in multiple files
Given a file named "string_spec.rb" with:
"""ruby
describe String do
it "has a failing example" do
"foo".reverse.should eq("ofo")
end
end
"""
And a file named "integer_spec.rb" with:
"""ruby
describe Integer do
it "has a failing example" do
(7 + 5).should eq(11)
end
end
"""
When I run `rspec integer_spec.rb string_spec.rb`
Then the backtrace-normalized output should contain:
"""
1) Integer has a failing example
Failure/Error: (7 + 5).should eq(11)
expected: 11
got: 12
(compared using ==)
# ./integer_spec.rb:3
"""
And the backtrace-normalized output should contain:
"""
2) String has a failing example
Failure/Error: "foo".reverse.should eq("ofo")
expected: "ofo"
got: "oof"
(compared using ==)
# ./string_spec.rb:3
"""
rspec-core-2.14.7/features/formatters/configurable_colors.feature 0000644 0000041 0000041 00000002250 12261207027 025277 0 ustar www-data www-data Feature: Configurable colors
RSpec allows you to configure the terminal colors used in the text formatters.
* `failure_color`: Color used when tests fail (default: `:red`)
* `success_color`: Color used when tests pass (default: `:green`)
* `pending_color`: Color used when tests are pending (default: `:yellow`)
* `fixed_color`: Color used when a pending block inside an example passes, but was expected to fail (default: `:blue`)
* `detail_color`: Color used for miscellaneous test details (default: `:cyan`)
Colors are normally specified as symbols. Options are `:black`, `:red`,
`:green`, `:yellow`, `:blue`, `:magenta`, `:cyan`, and `:white`.
@ansi
Scenario: Customizing the failure color
Given a file named "custom_failure_color_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.failure_color = :magenta
config.tty = true
config.color = true
end
describe "failure" do
it "fails and uses the custom color" do
expect(2).to eq(4)
end
end
"""
When I run `rspec custom_failure_color_spec.rb --format progress`
Then the failing example is printed in magenta
rspec-core-2.14.7/features/command_line/ 0000755 0000041 0000041 00000000000 12261207027 020141 5 ustar www-data www-data rspec-core-2.14.7/features/command_line/line_number_appended_to_path.feature 0000644 0000041 0000041 00000013475 12261207027 027405 0 ustar www-data www-data Feature: line number appended to file path
To run one or more examples or groups, you can append the line number to the path, e.g.
rspec path/to/example_spec.rb:37
Background:
Given a file named "example_spec.rb" with:
"""ruby
describe "outer group" do
it "first example in outer group" do
end
it "second example in outer group" do
end
describe "nested group" do
it "example in nested group" do
end
end
end
"""
And a file named "example2_spec.rb" with:
"""ruby
describe "yet another group" do
it "first example in second file" do
end
it "second example in second file" do
end
end
"""
Scenario: nested groups - outer group on declaration line
When I run `rspec example_spec.rb:1 --format doc`
Then the examples should all pass
And the output should contain "second example in outer group"
And the output should contain "first example in outer group"
And the output should contain "example in nested group"
Scenario: nested groups - outer group inside block before example
When I run `rspec example_spec.rb:2 --format doc`
Then the examples should all pass
And the output should contain "second example in outer group"
And the output should contain "first example in outer group"
And the output should contain "example in nested group"
Scenario: nested groups - inner group on declaration line
When I run `rspec example_spec.rb:11 --format doc`
Then the examples should all pass
And the output should contain "example in nested group"
And the output should not contain "second example in outer group"
And the output should not contain "first example in outer group"
Scenario: nested groups - inner group inside block before example
When I run `rspec example_spec.rb:12 --format doc`
Then the examples should all pass
And the output should contain "example in nested group"
And the output should not contain "second example in outer group"
And the output should not contain "first example in outer group"
Scenario: two examples - first example on declaration line
When I run `rspec example_spec.rb:3 --format doc`
Then the examples should all pass
And the output should contain "first example in outer group"
But the output should not contain "second example in outer group"
And the output should not contain "example in nested group"
Scenario: two examples - first example inside block
When I run `rspec example_spec.rb:4 --format doc`
Then the examples should all pass
And the output should contain "first example in outer group"
But the output should not contain "second example in outer group"
And the output should not contain "example in nested group"
Scenario: two examples - first example on end
When I run `rspec example_spec.rb:5 --format doc`
Then the examples should all pass
And the output should contain "first example in outer group"
But the output should not contain "second example in outer group"
And the output should not contain "example in nested group"
Scenario: two examples - first example after end but before next example
When I run `rspec example_spec.rb:6 --format doc`
Then the examples should all pass
And the output should contain "first example in outer group"
But the output should not contain "second example in outer group"
And the output should not contain "example in nested group"
Scenario: two examples - second example on declaration line
When I run `rspec example_spec.rb:7 --format doc`
Then the examples should all pass
And the output should contain "second example in outer group"
But the output should not contain "first example in outer group"
And the output should not contain "example in nested group"
Scenario: two examples - second example inside block
When I run `rspec example_spec.rb:7 --format doc`
Then the examples should all pass
And the output should contain "second example in outer group"
But the output should not contain "first example in outer group"
And the output should not contain "example in nested group"
Scenario: two examples - second example on end
When I run `rspec example_spec.rb:7 --format doc`
Then the examples should all pass
And the output should contain "second example in outer group"
But the output should not contain "first example in outer group"
And the output should not contain "example in nested group"
Scenario: specified multiple times for different files
When I run `rspec example_spec.rb:7 example2_spec.rb:4 --format doc`
Then the examples should all pass
And the output should contain "second example in outer group"
And the output should contain "second example in second file"
But the output should not contain "first example in outer group"
And the output should not contain "nested group"
And the output should not contain "first example in second file"
Scenario: specified multiple times for the same file with multiple arguments
When I run `rspec example_spec.rb:7 example_spec.rb:11 --format doc`
Then the examples should all pass
And the output should contain "second example in outer group"
And the output should contain "nested group"
But the output should not contain "first example in outer group"
And the output should not contain "second file"
Scenario: specified multiple times for the same file with a single argument
When I run `rspec example_spec.rb:7:11 --format doc`
Then the examples should all pass
And the output should contain "second example in outer group"
And the output should contain "nested group"
But the output should not contain "first example in outer group"
And the output should not contain "second file"
rspec-core-2.14.7/features/command_line/pattern_option.feature 0000644 0000041 0000041 00000002447 12261207027 024572 0 ustar www-data www-data Feature: pattern option
By default, RSpec loads files matching the pattern:
"spec/**/*_spec.rb"
Use the `--pattern` option to declare a different pattern.
Scenario: default pattern
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "addition" do
it "adds things" do
(1 + 2).should eq(3)
end
end
"""
When I run `rspec`
Then the output should contain "1 example, 0 failures"
Scenario: override the default pattern on the command line
Given a file named "spec/example.spec" with:
"""ruby
describe "addition" do
it "adds things" do
(1 + 2).should eq(3)
end
end
"""
When I run `rspec --pattern "spec/**/*.spec"`
Then the output should contain "1 example, 0 failures"
Scenario: override the default pattern in configuration
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure do |config|
config.pattern << ',**/*.spec'
end
"""
And a file named "spec/example.spec" with:
"""ruby
describe "addition" do
it "adds things" do
(1 + 2).should eq(3)
end
end
"""
When I run `rspec -rspec_helper`
Then the output should contain "1 example, 0 failures"
rspec-core-2.14.7/features/command_line/require_option.feature 0000644 0000041 0000041 00000002331 12261207027 024561 0 ustar www-data www-data Feature: --require option
Use the `--require` (or `-r`) option to specify a file to require
before running specs.
Scenario: using the --require option
Given a file named "logging_formatter.rb" with:
"""ruby
require "rspec/core/formatters/base_text_formatter"
require 'delegate'
class LoggingFormatter < RSpec::Core::Formatters::BaseTextFormatter
def initialize(output)
super LoggingIO.new(output)
end
class LoggingIO < SimpleDelegator
def initialize(output)
@file = File.new('rspec.log', 'w')
super
end
def puts(message)
[@file, __getobj__].each { |out| out.puts message }
end
def close
@file.close
end
end
end
"""
And a file named "spec/example_spec.rb" with:
"""ruby
describe "an embarassing situation" do
it "happens to everyone" do
end
end
"""
When I run `rspec --require ./logging_formatter.rb --format LoggingFormatter`
Then the output should contain "1 example, 0 failures"
And the file "rspec.log" should contain "1 example, 0 failures"
And the exit status should be 0
rspec-core-2.14.7/features/command_line/format_option.feature 0000644 0000041 0000041 00000004457 12261207027 024410 0 ustar www-data www-data Feature: --format option
Use the --format option to tell RSpec how to format the output.
RSpec ships with several formatters built in. By default, it uses the progress
formatter, which generates output like this:
....F.....*.....
A '.' represents a passing example, 'F' is failing, and '*' is pending.
Use the documentation formatter to see the documentation strings passed to
`describe`, `it`, and their aliases:
$ rspec spec --format documentation
You can also specify an output target ($stdout by default) with an --out
option immediately following the --format option:
$ rspec spec --format documentation --out rspec.txt
Run `rspec --help` to see a listing of available formatters.
Background:
Given a file named "example_spec.rb" with:
"""ruby
describe "something" do
it "does something that passes" do
5.should eq(5)
end
it "does something that fails" do
5.should eq(4)
end
it "does something that is pending", :pending => true do
5.should be > 3
end
end
"""
Scenario: progress bar format (default)
When I run `rspec --format progress example_spec.rb`
Then the output should contain ".F*"
Scenario: documentation format
When I run `rspec example_spec.rb --format documentation`
Then the output should contain:
"""
something
does something that passes
does something that fails (FAILED - 1)
does something that is pending (PENDING: No reason given)
"""
Scenario: documentation format saved to a file
When I run `rspec example_spec.rb --format documentation --out rspec.txt`
Then the file "rspec.txt" should contain:
"""
something
does something that passes
does something that fails (FAILED - 1)
does something that is pending (PENDING: No reason given)
"""
Scenario: multiple formats and output targets
When I run `rspec example_spec.rb --format progress --format documentation --out rspec.txt`
Then the output should contain ".F*"
And the file "rspec.txt" should contain:
"""
something
does something that passes
does something that fails (FAILED - 1)
does something that is pending (PENDING: No reason given)
"""
rspec-core-2.14.7/features/command_line/exit_status.feature 0000644 0000041 0000041 00000004431 12261207027 024074 0 ustar www-data www-data Feature: exit status
The rspec command exits with an exit status of 0 if all examples pass,
and 1 if any examples fail. The failure exit code can be overridden
using the --failure-exit-code option.
Scenario: exit with 0 when all examples pass
Given a file named "ok_spec.rb" with:
"""ruby
describe "ok" do
it "passes" do
end
end
"""
When I run `rspec ok_spec.rb`
Then the exit status should be 0
And the examples should all pass
Scenario: exit with 1 when one example fails
Given a file named "ko_spec.rb" with:
"""ruby
describe "KO" do
it "fails" do
raise "KO"
end
end
"""
When I run `rspec ko_spec.rb`
Then the exit status should be 1
And the output should contain "1 example, 1 failure"
Scenario: exit with 1 when a nested examples fails
Given a file named "nested_ko_spec.rb" with:
"""ruby
describe "KO" do
describe "nested" do
it "fails" do
raise "KO"
end
end
end
"""
When I run `rspec nested_ko_spec.rb`
Then the exit status should be 1
And the output should contain "1 example, 1 failure"
Scenario: exit with 0 when no examples are run
Given a file named "a_no_examples_spec.rb" with:
"""ruby
"""
When I run `rspec a_no_examples_spec.rb`
Then the exit status should be 0
And the output should contain "0 examples"
Scenario: exit with 2 when one example fails and --failure-exit-code is 2
Given a file named "ko_spec.rb" with:
"""ruby
describe "KO" do
it "fails" do
raise "KO"
end
end
"""
When I run `rspec --failure-exit-code 2 ko_spec.rb`
Then the exit status should be 2
And the output should contain "1 example, 1 failure"
Scenario: exit with rspec's exit code when an at_exit hook is added upstream
Given a file named "exit_at_spec.rb" with:
"""ruby
require 'rspec/autorun'
at_exit { exit(0) }
describe "exit 0 at_exit" do
it "does not interfere with rspec's exit code" do
fail
end
end
"""
When I run `ruby exit_at_spec.rb`
Then the exit status should be 1
And the output should contain "1 example, 1 failure"
rspec-core-2.14.7/features/command_line/tag.feature 0000644 0000041 0000041 00000007006 12261207027 022274 0 ustar www-data www-data Feature: --tag option
Use the --tag (or -t) option to filter the examples by tags.
The tag can be a simple name or a name:value pair. In the first case,
examples with :name => true will be filtered. In the second case, examples
with :name => value will be filtered, where value is always a string. In
both cases, name is converted to a symbol.
Tags can also be used to exclude examples by adding a ~ before the tag. For
example ~tag will exclude all examples marked with :tag => true and
~tag:value will exclude all examples marked with :tag => value.
To be compatible with the Cucumber syntax, tags can optionally start with
an @ symbol, which will be ignored.
Background:
Given a file named "tagged_spec.rb" with:
"""ruby
describe "group with tagged specs" do
it "example I'm working now", :focus => true do; end
it "special example with string", :type => 'special' do; end
it "special example with symbol", :type => :special do; end
it "slow example", :skip => true do; end
it "ordinary example", :speed => 'slow' do; end
it "untagged example" do; end
end
"""
Scenario: filter examples with non-existent tag
When I run `rspec . --tag mytag`
Then the process should succeed even though no examples were run
Scenario: filter examples with a simple tag
When I run `rspec . --tag focus`
Then the output should contain "include {:focus=>true}"
And the examples should all pass
Scenario: filter examples with a simple tag and @
When I run `rspec . --tag @focus`
Then the output should contain "include {:focus=>true}"
Then the examples should all pass
Scenario: filter examples with a name:value tag
When I run `rspec . --tag type:special`
Then the output should contain:
"""
include {:type=>"special"}
"""
And the output should contain "2 examples"
And the examples should all pass
Scenario: filter examples with a name:value tag and @
When I run `rspec . --tag @type:special`
Then the output should contain:
"""
include {:type=>"special"}
"""
And the examples should all pass
Scenario: exclude examples with a simple tag
When I run `rspec . --tag ~skip`
Then the output should contain "exclude {:skip=>true}"
Then the examples should all pass
Scenario: exclude examples with a simple tag and @
When I run `rspec . --tag ~@skip`
Then the output should contain "exclude {:skip=>true}"
Then the examples should all pass
Scenario: exclude examples with a name:value tag
When I run `rspec . --tag ~speed:slow`
Then the output should contain:
"""
exclude {:speed=>"slow"}
"""
Then the examples should all pass
Scenario: exclude examples with a name:value tag and @
When I run `rspec . --tag ~@speed:slow`
Then the output should contain:
"""
exclude {:speed=>"slow"}
"""
Then the examples should all pass
Scenario: filter examples with a simple tag, exclude examples with another tag
When I run `rspec . --tag focus --tag ~skip`
Then the output should contain "include {:focus=>true}"
And the output should contain "exclude {:skip=>true}"
And the examples should all pass
Scenario: exclude examples with multiple tags
When I run `rspec . --tag ~skip --tag ~speed:slow`
Then the output should contain one of the following:
| exclude {:skip=>true, :speed=>"slow"} |
| exclude {:speed=>"slow", :skip=>true} |
Then the examples should all pass
rspec-core-2.14.7/features/command_line/rake_task.feature 0000644 0000041 0000041 00000005727 12261207027 023475 0 ustar www-data www-data Feature: rake task
RSpec ships with a rake task with a number of useful options
Scenario: default options with passing spec (prints command and exit status is 0)
Given a file named "Rakefile" with:
"""ruby
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
"""
And a file named "spec/thing_spec.rb" with:
"""ruby
describe "something" do
it "does something" do
# pass
end
end
"""
When I run `rake`
Then the output should match /(ruby|rbx) -S rspec/
Then the exit status should be 0
Scenario: default options with failing spec (exit status is 1)
Given a file named "Rakefile" with:
"""ruby
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
"""
And a file named "spec/thing_spec.rb" with:
"""ruby
describe "something" do
it "does something" do
fail
end
end
"""
When I run `rake`
Then the exit status should be 1
Scenario: fail_on_error = false with failing spec (exit status is 0)
Given a file named "Rakefile" with:
"""ruby
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.fail_on_error = false
end
task :default => :spec
"""
And a file named "spec/thing_spec.rb" with:
"""ruby
describe "something" do
it "does something" do
fail
end
end
"""
When I run `rake`
Then the exit status should be 0
Scenario: rspec_opts is specified in order to pass args to the rspec command
Given a file named "Rakefile" with:
"""ruby
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = "--tag fast"
end
"""
And a file named "spec/thing_spec.rb" with:
"""ruby
describe "something" do
it "has a tag", :fast => true do
# pass
end
it "does not have a tag" do
fail
end
end
"""
When I run `rake spec`
Then the exit status should be 0
Then the output should match:
"""
(ruby|rbx) -S rspec ./spec/thing_spec.rb --tag fast
"""
Scenario: rspec_opts is specified using arguments to the rake task
Given a file named "Rakefile" with:
"""ruby
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec, :tag) do |t, task_args|
t.rspec_opts = "--tag #{task_args[:tag]}"
end
"""
And a file named "spec/thing_spec.rb" with:
"""ruby
describe "something" do
it "has a tag", :fast => true do
# pass
end
it "does not have a tag" do
fail
end
end
"""
When I run `rake spec[fast]`
Then the exit status should be 0
Then the output should match:
"""
(ruby|rbx) -S rspec ./spec/thing_spec.rb --tag fast
"""
rspec-core-2.14.7/features/command_line/warnings_option.feature 0000644 0000041 0000041 00000001266 12261207027 024743 0 ustar www-data www-data Feature: run with warnings enabled
You can use the `--warnings` option to run specs with warnings enabled
@unsupported-on-rbx
Scenario:
Given a file named "example_spec.rb" with:
"""ruby
describe do
it 'generates warning' do
@undefined
end
end
"""
When I run `rspec --warnings example_spec.rb`
Then the output should contain "warning"
@unsupported-on-rbx
Scenario:
Given a file named "example_spec.rb" with:
"""ruby
describe do
it 'generates warning' do
@undefined
end
end
"""
When I run `rspec example_spec.rb`
Then the output should not contain "warning"
rspec-core-2.14.7/features/command_line/order.feature 0000644 0000041 0000041 00000002024 12261207027 022627 0 ustar www-data www-data Feature: --order (new in rspec-core-2.8)
Use the `--order` option to tell RSpec how to order the files, groups, and
examples. Options are `default` and `rand`:
Default is:
* files are ordered based on the underlying file system's order (typically
case-sensitive alpha on *nix OS's and case-insenstive alpha in Windows)
* groups/examples are loaded in the order in which they are declared
Use `rand` to randomize the order of files, groups within files, and
examples within groups.*
* Nested groups are always run from top-level to bottom-level in order to avoid
executing `before(:all)` and `after(:all)` hooks more than once, but the order
of groups at each level is randomized.
You can also specify a seed
Examples
--order default
--order rand
--order rand:123
--seed 123 # same as --order rand:123
The `default` option is only necessary when you have `--order rand` stored in a
config file (e.g. `.rspec`) and you want to override it from the command line.
rspec-core-2.14.7/features/command_line/line_number_option.feature 0000644 0000041 0000041 00000003053 12261207027 025406 0 ustar www-data www-data Feature: --line_number option
To run a examples or groups by line numbers, one can use the --line_number option:
rspec path/to/example_spec.rb --line_number 37
This option can be specified multiple times.
Scenario: standard examples
Given a file named "example_spec.rb" with:
"""ruby
require "rspec/expectations"
describe 9 do
it "should be > 8" do
9.should be > 8
end
it "should be < 10" do
9.should be < 10
end
it "should be 3 squared" do
9.should be 3*3
end
end
"""
When I run `rspec example_spec.rb --line_number 5 --format doc`
Then the examples should all pass
And the output should contain "should be > 8"
But the output should not contain "should be < 10"
And the output should not contain "should be 3*3"
When I run `rspec example_spec.rb --line_number 5 --line_number 9 --format doc`
Then the examples should all pass
And the output should contain "should be > 8"
And the output should contain "should be < 10"
But the output should not contain "should be 3*3"
Scenario: one liner
Given a file named "example_spec.rb" with:
"""ruby
require "rspec/expectations"
describe 9 do
it { should be > 8 }
it { should be < 10 }
end
"""
When I run `rspec example_spec.rb --line_number 5 --format doc`
Then the examples should all pass
Then the output should contain "should be > 8"
But the output should not contain "should be < 10"
rspec-core-2.14.7/features/command_line/example_name_option.feature 0000644 0000041 0000041 00000006461 12261207027 025550 0 ustar www-data www-data Feature: --example option
Use the --example (or -e) option to filter examples by name.
The argument is matched against the full description of the example,
which is the concatenation of descriptions of the group (including
any nested groups) and the example.
This allows you to run a single uniquely named example, all examples with
similar names, all the examples in a uniquely named group, etc, etc.
You can also use the option more than once to specify multiple example matches.
Background:
Given a file named "first_spec.rb" with:
"""ruby
describe "first group" do
it "first example in first group" do; end
it "second example in first group" do; end
end
"""
And a file named "second_spec.rb" with:
"""ruby
describe "second group" do
it "first example in second group" do; end
it "second example in second group" do; end
end
"""
And a file named "third_spec.rb" with:
"""ruby
describe "third group" do
it "first example in third group" do; end
context "nested group" do
it "first example in nested group" do; end
it "second example in nested group" do; end
end
end
"""
And a file named "fourth_spec.rb" with:
"""ruby
describe Array do
describe "#length" do
it "is the number of items" do
Array.new([1,2,3]).length.should eq 3
end
end
end
"""
Scenario: no matches
When I run `rspec . --example nothing_like_this`
Then the process should succeed even though no examples were run
Scenario: match on one word
When I run `rspec . --example example`
Then the examples should all pass
Scenario: one match in each context
When I run `rspec . --example 'first example'`
Then the examples should all pass
Scenario: one match in one file using just the example name
When I run `rspec . --example 'first example in first group'`
Then the examples should all pass
Scenario: one match in one file using the example name and the group name
When I run `rspec . --example 'first group first example in first group'`
Then the examples should all pass
Scenario: all examples in one group
When I run `rspec . --example 'first group'`
Then the examples should all pass
Scenario: one match in one file with group name
When I run `rspec . --example 'second group first example'`
Then the examples should all pass
Scenario: all examples in one group including examples in nested groups
When I run `rspec . --example 'third group'`
Then the examples should all pass
Scenario: Object#method
When I run `rspec . --example 'Array#length'`
Then the examples should all pass
Scenario: Multiple applications of example name option
When I run `rspec . --example 'first group' --example 'second group' --format d`
Then the examples should all pass
And the output should contain all of these:
|first example in first group|
|second example in first group|
|first example in second group|
|second example in second group|
And the output should not contain any of these:
|first example in third group|
|nested group first example in nested group|
|nested group second example in nested group|
rspec-core-2.14.7/features/command_line/init.feature 0000644 0000041 0000041 00000000750 12261207027 022463 0 ustar www-data www-data Feature: --init option
Use the --init option on the command line to generate conventional
files for an rspec project.
Scenario: generate .rspec
When I run `rspec --init`
Then the following files should exist:
| .rspec |
And the output should contain "create .rspec"
Scenario: .rspec file already exists
Given a file named ".rspec" with:
"""
--color
"""
When I run `rspec --init`
Then the output should contain "exist .rspec"
rspec-core-2.14.7/features/command_line/README.md 0000644 0000041 0000041 00000002021 12261207027 021413 0 ustar www-data www-data The `rspec` command comes with several options you can use to customize RSpec's
behavior, including output formats, filtering examples, etc.
For a full list of options, run the `rspec` command with the `--help` flag:
$ rspec --help
### Run with `ruby`
Generally, life is simpler if you just use the `rspec` command. If you must use the `ruby`
command, however, you'll want to do the following:
* `require 'rspec/autorun'`
This tells RSpec to run your examples. Do this in any file that you are
passing to the `ruby` command.
* Update the `LOAD_PATH`
It is conventional to put configuration in and require assorted support files
from `spec/spec_helper.rb`. It is also conventional to require that file from
the spec files using `require 'spec_helper'`. This works because RSpec
implicitly adds the `spec` directory to the `LOAD_PATH`. It also adds `lib`, so
your implementation files will be on the `LOAD_PATH` as well.
If you're using the `ruby` command, you'll need to do this yourself:
ruby -Ilib -Ispec path/to/spec.rb
rspec-core-2.14.7/features/command_line/ruby.feature 0000644 0000041 0000041 00000001114 12261207027 022474 0 ustar www-data www-data Feature: run with ruby command
You can use the `ruby` command to run specs. You just need to require
`rspec/autorun`.
Generally speaking, you're better off using the `rspec` command, which
requires `rspec/autorun` for you, but some tools only work with the `ruby`
command.
Scenario:
Given a file named "example_spec.rb" with:
"""ruby
require 'rspec/autorun'
describe 1 do
it "is < 2" do
1.should be < 2
end
end
"""
When I run `ruby example_spec.rb`
Then the output should contain "1 example, 0 failures"
rspec-core-2.14.7/features/Upgrade.md 0000644 0000041 0000041 00000026224 12261207027 017433 0 ustar www-data www-data The [Changelog](changelog) has a complete list of everything that changed, but
here are more detailed explanations for those items that warrant them.
# rspec-core-2.7.0.rc1
## what's new
### `rspec` command with no arguments
Now you can just type
rspec
to run all the specs in the `spec` directory. If you keep your specs in a
different directory, you can override the default with the `--default_path`
argument in a config file:
# in .rspec
--default_path specs
### `rspec` command supports multiple line numbers
Use either of the following to run the examples declared on lines
37 and 42 of `a_spec.rb`:
rspec path/to/a_spec.rb --line_number 37 --line_number 42
rspec path/to/a_spec.rb:37:42
## what's changed
### `skip_bundler` and `gemfile` rake task options are deprecated and have no effect.
RSpec's rake task invokes the `rspec` command in a subshell. If you invoke
`bundle exec rake` or include `Bundler.setup` in your `Rakefile`, then
Bundler will be activated in the subshell as well.
Previously, the rake task managed this for you based on the presence of a
`Gemfile`. In 2.7.0.rc1, this is done based on the presence of the
`BUNDLE_GEMFILE` environment variable, which is set in the parent shell by Bundler.
In 2.7.0.rc2 (not yet released), the rake task doesn't do anything at all.
Turns out Bundler just does the right thing, so rspec doesn't need to do
anything.
# rspec-core-2.6
## new APIs for sharing content
Use `shared_context` together with `include_context` to share before/after
hooks, let declarations, and method definitions across example groups.
Use `shared_examples` together with `include_examples` to share examples
across different contexts.
All of the old APIs are still supported, but these 4 are easy to remember, and
serve most use cases.
See `shared_context` and `shared_examples` under "Example Groups" for more
information.
## `treat_symbols_as_metadata_keys_with_true_values`
Yes it's a long name, but it's a great feature, and it's going to be the
default behavior in rspec-3. This lets you add metadata to a group or example
like this:
describe "something", :awesome do
...
And then you can run that group (or example) using the tags feature:
rspec spec --tag awesome
We're making this an opt-in for rspec-2.6 because `describe "string", :symbol`
is a perfectly legal construct in pre-2.6 releases and we want to maintain
compatibility in minor releases as much as is possible.
# rspec-core-2.3
## `config.expect_with`
Use this to configure RSpec to use rspec/expectations (default),
stdlib assertions (Test::Unit with Ruby 1.8, MiniTest with Ruby 1.9),
or both:
RSpec.configure do |config|
config.expect_with :rspec # => rspec/expectations
config.expect_with :stdlib # => Test::Unit or MinitTest
config.expect_with :rspec, :stdlib # => both
end
# rspec-core-2.1
## Command line
### `--tags`
Now you can tag groups and examples using metadata and access those tags from
the command line. So if you have a group with `:foo => true`:
describe "something", :foo => true do
it "does something" do
# ...
end
end
... now you can run just that group like this:
rspec spec --tags foo
### `--fail-fast`
Add this flag to the command line to tell rspec to clean up and exit after the
first failure:
rspec spec --fail-fast
## Metata/filtering
### :if and :unless keys
Use :if and :unless keys to conditionally run examples with simple boolean
expressions:
describe "something" do
it "does something", :if => RUBY_VERSION == 1.8.6 do
# ...
end
it "does something", :unless => RUBY_VERSION == 1.8.6 do
# ...
end
end
## Conditionally 'pending' examples
Make examples pending based on a condition. This is most useful when you
have an example that runs in multiple contexts and fails in one of those due to
a bug in a third-party dependency that you expect to be fixed in the future.
describe "something" do
it "does something that doesn't yet work right on JRuby" do
pending("waiting for the JRuby team to fix issue XYZ", :if => RUBY_PLATFORM == 'java') do
# the content of your spec
end
end
end
This example would run normally on all ruby interpretters except JRuby. On JRuby,
it uses the block form of `pending`, which causes the example to still be run and
will remain pending as long as it fails. In the future, if you upgraded your
JRuby installation to a newer release that allows the example to pass, RSpec
will report it as a failure (`Expected pending '...' to fail. No Error was raised.`),
so that know that you can remove the call to `pending`.
# New features in rspec-core-2.0
### Runner
The new runner for rspec-2 comes from Micronaut.
### Metadata!
In rspec-2, every example and example group comes with metadata information
like the file and line number on which it was declared, the arguments passed to
`describe` and `it`, etc. This metadata can be appended to through a hash
argument passed to `describe` or `it`, allowing us to pre and post-process
each example in a variety of ways.
### Filtering
The most obvious use is for filtering the run. For example:
# in spec/spec_helper.rb
RSpec.configure do |c|
c.filter_run :focus => true
end
# in any spec file
describe "something" do
it "does something", :focus => true do
# ....
end
end
When you run the `rspec` command, rspec will run only the examples that have
`:focus => true` in the hash.
You can also add `run_all_when_everything_filtered` to the config:
RSpec.configure do |c|
c.filter_run :focus => true
c.run_all_when_everything_filtered = true
end
Now if there are no examples tagged with `:focus => true`, all examples
will be run. This makes it really easy to focus on one example for a
while, but then go back to running all of the examples by removing that
argument from `it`. Works with `describe` too, in which case it runs
all of the examples in that group.
The configuration will accept a lambda, which provides a lot of flexibility
in filtering examples. Say, for example, you have a spec for functionality that
behaves slightly differently in Ruby 1.8 and Ruby 1.9. We have that in
rspec-core, and here's how we're getting the right stuff to run under the
right version:
# in spec/spec_helper.rb
RSpec.configure do |c|
c.exclusion_filter = { :ruby => lambda {|version|
!(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
}}
end
# in any spec file
describe "something" do
it "does something", :ruby => 1.8 do
# ....
end
it "does something", :ruby => 1.9 do
# ....
end
end
In this case, we're using `exclusion_filter` instead of `filter_run` or
`filter`, which indicate _inclusion_ filters. So each of those examples is
excluded if we're _not_ running the version of Ruby they work with.
### Shared example groups
Shared example groups are now run in a nested group within the including group
(they used to be run in the same group). Nested groups inherit `before`, `after`,
`around`, and `let` hooks, as well as any methods that are defined in the parent
group.
This new approach provides better encapsulation, better output, and an
opportunity to add contextual information to the shared group via a block
passed to `it_should_behave_like`.
See [features/example\_groups/shared\_example\_group.feature](http://github.com/rspec/rspec-core/blob/master/features/example_groups/shared_example_group.feature) for more information.
NOTICE: The including example groups no longer have access to any of the
methods, hooks, or state defined inside a shared group. This will break rspec-1
specs that were using shared example groups to extend the behavior of including
groups.
# Upgrading from rspec-1.x
### rspec command
The command to run specs is now `rspec` instead of `spec`.
rspec ./spec
#### Co-habitation of rspec-1 and rspec-2
Early beta versions of RSpec-2 included a `spec` command, which conflicted with
the RSpec-1 `spec` command because RSpec-1's was installed by the rspec gem,
while RSpec-2's is installed by the rspec-core gem.
If you installed one of these early versions, the safest bet is to uninstall
rspec-1 and rspec-core-2, and then reinstall both. After you do this, you will
be able to run rspec-2 like this:
rspec ./spec
... and rspec-1 like this:
spec _1.3.1_ ./spec
Rubygems inspects the first argument to any gem executable to see if it's
formatted like a version number surrounded by underscores. If so, it uses that
version (e.g. `1.3.1`). If not, it uses the most recent version (e.g.
`2.0.0`).
### rake task
A few things changed in the Rake task used to run specs:
1. The file in which it is defined changed from `spec/rake/spectask` to
`rspec/core/rake_task`
2. The `spec_opts` accessor has been deprecated in favor of `rspec_opts`. Also,
the `rspec` command no longer supports the `--options` command line option
so the options must be embedded directly in the Rakefile, or stored in the
`.rspec` files mentioned above.
3. In RSpec-1, the rake task would read in rcov options from an `rcov.opts`
file. This is ignored by RSpec-2. RCov options are now set directly on the Rake
task:
RSpec::Core::RakeTask.new(:rcov) do |t|
t.rcov_opts = %q[--exclude "spec"]
end
3. The `spec_files` accessor has been replaced by `pattern`.
# rspec-1
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new do |t|
t.spec_opts = ['--options', "\"spec/spec.opts\""]
t.spec_files = FileList['spec/**/*.rb']
end
# rspec-2
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new do |t|
t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
t.pattern = 'spec/**/*_spec.rb'
end
### autotest
`autospec` is dead. Long live `autotest`.
### RSpec is the new Spec
The root namespace (top level module) is now `RSpec` instead of `Spec`, and
the root directory under `lib` within all of the `rspec` gems is `rspec` instead of `spec`.
### Configuration
Typically in `spec/spec_helper.rb`, configuration is now done like this:
RSpec.configure do |c|
# ....
end
### .rspec
Command line options can be persisted in a `.rspec` file in a project. You
can also store a `.rspec` file in your home directory (`~/.rspec`) with global
options. Precedence is:
command line
./.rspec
~/.rspec
### `context` is no longer a top-level method
We removed `context` from the main object because it was creating conflicts with
IRB and some users who had `Context` domain objects. `describe` is still there,
so if you want to use `context` at the top level, just alias it:
alias :context :describe
Of course, you can still use `context` to declare a nested group:
describe "something" do
context "in some context" do
it "does something" do
# ...
end
end
end
### `$KCODE` no longer set implicitly to `'u'`
In RSpec-1, the runner set `$KCODE` to `'u'`, which impacts, among other
things, the behaviour of Regular Expressions when applied to non-ascii
characters. This is no longer the case in RSpec-2.
rspec-core-2.14.7/features/expectation_framework_integration/ 0000755 0000041 0000041 00000000000 12261207027 024517 5 ustar www-data www-data rspec-core-2.14.7/features/expectation_framework_integration/configure_expectation_framework.feature0000644 0000041 0000041 00000005467 12261207027 034551 0 ustar www-data www-data Feature: configure expectation framework
By default, RSpec is configured to include rspec-expectations for expressing
desired outcomes. You can also configure RSpec to use:
* rspec/expectations (explicitly)
* stdlib assertions
* test/unit assertions in ruby 1.8
* minitest assertions in ruby 1.9
* rspec/expectations _and_ stlib assertions
Note that when you do not use rspec-expectations, you must explicitly
provide a description to every example. You cannot rely on the generated
descriptions provided by rspec-expectations.
Scenario: rspec-expectations can be used by default if nothing is configured
Given a file named "example_spec.rb" with:
"""ruby
RSpec::Matchers.define :be_a_multiple_of do |factor|
match do |actual|
actual % factor == 0
end
end
describe 6 do
it { should be_a_multiple_of(3) }
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
Scenario: configure rspec-expectations (explicitly)
Given a file named "example_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.expect_with :rspec
end
describe 5 do
it "is greater than 4" do
5.should be > 4
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
Scenario: configure test/unit assertions (passing examples)
Given a file named "example_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.expect_with :stdlib
end
describe 5 do
it "is greater than 4" do
assert 5 > 4, "expected 5 to be greater than 4"
end
specify { assert 5 < 6 }
end
"""
When I run `rspec example_spec.rb`
Then the output should contain "2 examples, 0 failures"
Scenario: configure test/unit assertions (failing examples)
Given a file named "example_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.expect_with :stdlib
end
describe 5 do
it "is greater than 6 (no it isn't!)" do
assert 5 > 6, "errantly expected 5 to be greater than 5"
end
specify { assert 5 > 6 }
end
"""
When I run `rspec example_spec.rb`
Then the output should contain "2 examples, 2 failures"
Scenario: configure rspec/expecations AND test/unit assertions
Given a file named "example_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.expect_with :rspec, :stdlib
end
describe 5 do
it "is greater than 4" do
assert 5 > 4, "expected 5 to be greater than 4"
end
it "is less than 6" do
5.should be < 6
end
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
rspec-core-2.14.7/features/support/ 0000755 0000041 0000041 00000000000 12261207027 017230 5 ustar www-data www-data rspec-core-2.14.7/features/support/rubinius.rb 0000644 0000041 0000041 00000000341 12261207027 021413 0 ustar www-data www-data # Required until https://github.com/rubinius/rubinius/issues/2430 is resolved
ENV['RBXOPT'] = "#{ENV["RBXOPT"]} -Xcompiler.no_rbc"
Around "@unsupported-on-rbx" do |scenario, block|
block.call unless defined?(Rubinius)
end
rspec-core-2.14.7/features/support/env.rb 0000644 0000041 0000041 00000000523 12261207027 020345 0 ustar www-data www-data require 'aruba/cucumber'
timeouts = { 'java' => 60 }
Before do
@aruba_timeout_seconds = timeouts.fetch(RUBY_PLATFORM) { 10 }
end
Aruba.configure do |config|
config.before_cmd do |cmd|
set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived
end
end if RUBY_PLATFORM == 'java'
rspec-core-2.14.7/features/README.md 0000644 0000041 0000041 00000001133 12261207027 016771 0 ustar www-data www-data rspec-core provides the structure for RSpec code examples:
describe Account do
it "has a balance of zero when first opened" do
# example code goes here - for more on the
# code inside the examples, see rspec-expectations
# and rspec-mocks
end
end
## Issues
This documentation is [open
source](https://github.com/rspec/rspec-core/tree/master/features), and a work
in progress. If you find it incomplete or confusing, please [submit an
issue](http://github.com/rspec/rspec-core/issues), or, better yet, [a pull
request](http://github.com/rspec/rspec-core).
rspec-core-2.14.7/Changelog.md 0000644 0000041 0000041 00000106541 12261207027 016116 0 ustar www-data www-data ### 2.14.7 / 2013-10-29
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.6...v2.14.7)
Bug fixes:
* Fix regression in 2.14.6 that broke the Fivemat formatter.
It depended upon either
`example.execution_result[:exception].pending_fixed?` (which
was removed in 2.14.6 to fix an issue with frozen error objects)
or `RSpec::Core::PendingExampleFixedError` (which was renamed
to `RSpec::Core::Pending::PendingExampleFixedError` in 2.8.
This fix makes a constant alias for the old error name.
(Myron Marston)
### 2.14.6 / 2013-10-15
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.5...v2.14.6)
Bug fixes:
* Format stringified numbers correctly when mathn library is loaded.
(Jay Hayes)
* Fix an issue that prevented the use of frozen error objects. (Lars Gierth)
### 2.14.5 / 2013-08-13
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.4...v2.14.5)
Bug fixes:
* Fix a `NoMethodError` that was being raised when there were no shared
examples or contexts declared and `RSpec.world.reset` is invoked.
(thepoho, Jon Rowe, Myron Marston)
* Fix a deprecation warning that was being incorrectly displayed when
`shared_examples` are declared at top level in a `module` scope.
(Jon Rowe)
* Fix after(:all) hooks so consecutive (same context) scopes will run even if
one raises an error. (Jon Rowe, Trejkaz)
* JsonFormatter no longer dies if `dump_profile` isn't defined (Alex / @MasterLambaster, Jon Rowe)
### 2.14.4 / 2013-07-21
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.3...v2.14.4)
Bug fixes
* Fix regression in 2.14: ensure configured requires (via `-r` option)
are loaded before spec files are loaded. This allows the spec files
to programatically change the file pattern (Jon Rowe).
* Autoload `RSpec::Mocks` and `RSpec::Expectations` when referenced if
they are not already loaded (`RSpec::Matches` has been autoloaded
for a while). In the `rspec` gem, we changed it recently to stop
loading `rspec/mocks` and `rspec/expectations` by default, as some
users reported problems where they were intending to use mocha,
not rspec-mocks, but rspec-mocks was loaded and causing a conflict.
rspec-core loads mocks and expectations at the appropriate time, so
it seemed like a safe change -- but caused a problem for some authors
of libraries that integrate with RSpec. This fixes that problem.
(Myron Marston)
* Gracefully handle a command like `rspec --profile path/to/spec.rb`:
the `path/to/spec.rb` arg was being wrongly treated as the `profile`
integer arg, which got cast `0` using `to_i`, causing no profiled
examples to be printed. (Jon Rowe)
### 2.14.3 / 2013-07-13
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.2...v2.14.3)
Bug fixes
* Fix deprecation notices issued from `RSpec::Core::RakeTask` so
that they work properly when all of rspec-core is not loaded.
(This was a regression in 2.14) (Jon Rowe)
### 2.14.2 / 2013-07-09
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.1...v2.14.2)
Bug fixes
* Fix regression caused by 2.14.1 release: formatters that
report that they `respond_to?` a notification, but had
no corresponding method would raise an error when registered.
The new fix is to just implement `start` on the deprecation
formatter to fix the original JRuby/ruby-debug issue.
(Jon Rowe)
### 2.14.1 / 2013-07-08
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.0...v2.14.1)
Bug fixes
* Address deprecation formatter failure when using `ruby-debug` on
JRuby: fix `RSpec::Core::Reporter` to not send a notification
when the formatter's implementation of the notification method
comes from `Kernel` (Alex Portnov, Jon Rowe).
### 2.14.0 / 2013-07-06
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.0.rc1...v2.14.0)
Enhancements
* Apply focus to examples defined with `fit` (equivalent of
`it "description", focus: true`) (Michael de Silva)
Bug fixes
* Ensure methods defined by `let` take precedence over others
when there is a name collision (e.g. from an included module).
(Jon Rowe, Andy Lindeman and Myron Marston)
### 2.14.0.rc1 / 2013-05-27
[full changelog](http://github.com/rspec/rspec-core/compare/v2.13.1...v2.14.0.rc1)
Enhancements
* Improved Windows detection inside Git Bash, for better `--color` handling.
* Add profiling of the slowest example groups to `--profile` option.
The output is sorted by the slowest average example groups.
* Don't show slow examples if there's a failure and both `--fail-fast`
and `--profile` options are used (Paweł Gościcki).
* Rather than always adding `spec` to the load path, add the configured
`--default-path` to the load path (which defaults to `spec`). This
better supports folks who choose to put their specs in a different
directory (John Feminella).
* Add some logic to test time duration precision. Make it a
function of time, dropping precision as the time increases. (Aaron Kromer)
* Add new `backtrace_inclusion_patterns` config option. Backtrace lines
that match one of these patterns will _always_ be included in the
backtrace, even if they match an exclusion pattern, too (Sam Phippen).
* Support ERB trim mode using the `-` when parsing `.rspec` as ERB
(Gabor Garami).
* Give a better error message when let and subject are called without a block.
(Sam Phippen).
* List the precedence of `.rspec-local` in the configuration documentation
(Sam Phippen)
* Support `{a,b}` shell expansion syntax in `--pattern` option
(Konstantin Haase).
* Add cucumber documentation for --require command line option
(Bradley Schaefer)
* Expose configruation options via config:
* `config.libs` returns the libs configured to be added onto the load path
* `full_backtrace?` returns the state of the backtrace cleaner
* `debug?` returns true when the debugger is loaded
* `line_numbers` returns the line numbers we are filtering by (if any)
* `full_description` returns the RegExp used to filter descriptions
(Jon Rowe)
* Add setters for RSpec.world and RSpec.configuration (Alex Soulim)
* Configure ruby's warning behaviour with `--warnings` (Jon Rowe)
* Fix an obscure issue on old versions of `1.8.7` where `Time.dup` wouldn't
allow access to `Time.now` (Jon Rowe)
* Make `shared_examples_for` context aware, so that keys may be safely reused
in multiple contexts without colliding. (Jon Rowe)
* Add a configurable `deprecation_stream` (Jon Rowe)
* Publish deprecations through a formatter (David Chelimsky)
Bug fixes
* Make JSON formatter behave the same when it comes to `--profile` as
the text formatter (Paweł Gościcki).
* Fix named subjects so that if an inner group defines a method that
overrides the named method, `subject` still retains the originally
declared value (Myron Marston).
* Fix random ordering so that it does not cause `rand` in examples in
nested sibling contexts to return the same value (Max Shytikov).
* Use the new `backtrace_inclusion_patterns` config option to ensure
that folks who develop code in a directory matching one of the default
exclusion patterns (e.g. `gems`) still get the normal backtrace
filtering (Sam Phippen).
* Fix ordering of `before` hooks so that `before` hooks declared in
`RSpec.configure` run before `before` hooks declared in a shared
context (Michi Huber and Tejas Dinkar).
* Fix `Example#full_description` so that it gets filled in by the last
matcher description (as `Example#description` already did) when no
doc string has been provided (David Chelimsky).
* Fix the memoized methods (`let` and `subject`) leaking `define_method`
as a `public` method. (Thomas Holmes and Jon Rowe) (#873)
* Fix warnings coming from the test suite. (Pete Higgins)
Deprecations
* Deprecate `Configuration#backtrace_clean_patterns` in favor of
`Configuration#backtrace_exclusion_patterns` for greater consistency
and symmetry with new `backtrace_inclusion_patterns` config option
(Sam Phippen).
* Deprecate `Configuration#requires=` in favor of using ruby's
`require`. Requires specified by the command line can still be
accessed by the `Configuration#require` reader. (Bradley Schaefer)
* Deprecate calling `SharedExampleGroups` defined across sibling contexts
(Jon Rowe)
### 2.13.1 / 2013-03-12
[full changelog](http://github.com/rspec/rspec-core/compare/v2.13.0...v2.13.1)
Bug fixes
* Use hook classes as proxies rather than extending hook blocks to support
lambdas for before/after/around hooks. (David Chelimsky)
* Fix regression in 2.13.0 that caused confusing behavior when overriding
a named subject with an unnamed subject in an inner group and then
referencing the outer group subject's name. The fix for this required
us to disallow using `super` in a named subject (which is confusing,
anyway -- named subjects create 2 methods, so which method on the
parent example group are you `super`ing to?) but `super` in an unnamed
subject continues to work (Myron Marston).
* Do not allow a referenced `let` or `subject` in `before(:all)` to cause
other `let` declarations to leak across examples (Myron Marston).
* Work around odd ruby 1.9 bug with `String#match` that was triggered
by passing it a regex from a `let` declaration. For more info, see
http://bugs.ruby-lang.org/issues/8059 (Aaron Kromer).
* Add missing `require 'set'` to `base_text_formatter.rb` (Tom
Anderson).
Deprecations
* Deprecate accessing `let` or `subject` declarations in `before(:all)`.
These were not intended to be called in a `before(:all)` hook, as
they exist to define state that is reset between each example, while
`before(:all)` exists to define state that is shared across examples
in an example group (Myron Marston).
### 2.13.0 / 2013-02-23
[full changelog](http://github.com/rspec/rspec-core/compare/v2.12.2...v2.13.0)
Enhancements
* Allow `--profile` option to take a count argument that
determines the number of slow examples to dump
(Greggory Rothmeier).
* Add `subject!` that is the analog to `let!`. It defines an
explicit subject and sets a `before` hook that will invoke
the subject (Zubin Henner).
* Fix `let` and `subject` declaration so that `super`
and `return` can be used in them, just like in a normal
method. (Myron Marston)
* Allow output colors to be configured individually.
(Charlie Maffitt)
* Always dump slow examples when `--profile` option is given,
even when an example failed (Myron Marston).
Bug fixes
* Don't blow up when dumping error output for instances
of anonymous error classes (Myron Marston).
* Fix default backtrace filters so lines from projects
containing "gems" in the name are not filtered, but
lines from installed gems still are (Myron Marston).
* Fix autotest command so that is uses double quotes
rather than single quotes for windows compatibility
(Jonas Tingeborn).
* Fix `its` so that uses of `subject` in a `before` or `let`
declaration in the parent group continue to reference the
parent group's subject. (Olek Janiszewski)
### 2.12.2 / 2012-12-13
[full changelog](http://github.com/rspec/rspec-core/compare/v2.12.1...v2.12.2)
Bug fixes
* Fix `RSpec::Core::RakeTask` so that it is compatible with rake 0.8.7
on ruby 1.8.7. We had accidentally broke it in the 2.12 release
(Myron Marston).
* Fix `RSpec::Core::RakeTask` so it is tolerant of the `Rspec` constant
for backwards compatibility (Patrick Van Stee)
### 2.12.1 / 2012-12-01
[full changelog](http://github.com/rspec/rspec-core/compare/v2.12.0...v2.12.1)
Bug fixes
* Specs are run even if another at\_exit hook calls `exit`. This allows
Test::Unit and RSpec to run together. (Suraj N. Kurapati)
* Fix full doc string concatenation so that it handles the case of a
method string (e.g. "#foo") being nested under a context string
(e.g. "when it is tuesday"), so that we get "when it is tuesday #foo"
rather than "when it is tuesday#foo". (Myron Marston)
* Restore public API I unintentionally broke in 2.12.0:
`RSpec::Core::Formatters::BaseFormatter#format_backtrce(backtrace, example)`
(Myron Marston).
### 2.12.0 / 2012-11-12
[full changelog](http://github.com/rspec/rspec-core/compare/v2.11.1...v2.12.0)
Enhancements
* Add support for custom ordering strategies for groups and examples.
(Myron Marston)
* JSON Formatter (Alex Chaffee)
* Refactor rake task internals (Sam Phippen)
* Refactor HtmlFormatter (Pete Hodgson)
* Autotest supports a path to Ruby that contains spaces (dsisnero)
* Provide a helpful warning when a shared example group is redefined.
(Mark Burns).
* `--default_path` can be specified as `--default-line`. `--line_number` can be
specified as `--line-number`. Hyphens are more idiomatic command line argument
separators (Sam Phippen).
* A more useful error message is shown when an invalid command line option is
used (Jordi Polo).
* Add `format_docstrings { |str| }` config option. It can be used to
apply formatting rules to example group and example docstrings.
(Alex Tan)
* Add support for an `.rspec-local` options file. This is intended to
allow individual developers to set options in a git-ignored file that
override the common project options in `.rspec`. (Sam Phippen)
* Support for mocha 0.13.0. (Andy Lindeman)
Bug fixes
* Remove override of `ExampleGroup#ancestors`. This is a core ruby method that
RSpec shouldn't override. Instead, define `ExampleGroup#parent_groups`. (Myron
Marston)
* Limit monkey patching of shared example/context declaration methods
(`shared_examples_for`, etc.) to just the objects that need it rather than
every object in the system (Myron Marston).
* Fix Metadata#fetch to support computed values (Sam Goldman).
* Named subject can now be referred to from within subject block in a nested
group (tomykaira).
* Fix `fail_fast` so that it properly exits when an error occurs in a
`before(:all) hook` (Bradley Schaefer).
* Make the order spec files are loaded consistent, regardless of the
order of the files returned by the OS or the order passed at
the command line (Jo Liss and Sam Phippen).
* Ensure instance variables from `before(:all)` are always exposed
from `after(:all)`, even if an error occurs in `before(:all)`
(Sam Phippen).
* `rspec --init` no longer generates an incorrect warning about `--configure`
being deprecated (Sam Phippen).
* Fix pluralization of `1 seconds` (Odin Dutton)
* Fix ANSICON url (Jarmo Pertman)
* Use dup of Time so reporting isn't clobbered by examples that modify Time
without properly restoring it. (David Chelimsky)
Deprecations
* `share_as` is no longer needed. `shared_context` and/or
`RSpec::SharedContext` provide better mechanisms (Sam Phippen).
* Deprecate `RSpec.configuration` with a block (use `RSpec.configure`).
### 2.11.1 / 2012-07-18
[full changelog](http://github.com/rspec/rspec-core/compare/v2.11.0...v2.11.1)
Bug fixes
* Fix the way we autoload RSpec::Matchers so that custom matchers can be
defined before rspec-core has been configured to definitely use
rspec-expectations. (Myron Marston)
* Fix typo in --help message printed for -e option. (Jo Liss)
* Fix ruby warnings. (Myron Marston)
* Ignore mock expectation failures when the example has already failed.
Mock expectation failures have always been ignored in this situation,
but due to my changes in 27059bf1 it was printing a confusing message.
(Myron Marston).
### 2.11.0 / 2012-07-07
[full changelog](http://github.com/rspec/rspec-core/compare/v2.10.1...v2.11.0)
Enhancements
* Support multiple `--example` options. (Daniel Doubrovkine @dblock)
* Named subject e.g. `subject(:article) { Article.new }`
* see [http://blog.davidchelimsky.net/2012/05/13/spec-smell-explicit-use-of-subject/](http://blog.davidchelimsky.net/2012/05/13/spec-smell-explicit-use-of-subject/)
for background.
* thanks to Bradley Schaefer for suggesting it and Avdi Grimm for almost
suggesting it.
* `config.mock_with` and `config.expect_with` yield custom config object to a
block if given
* aids decoupling from rspec-core's configuation
* `include_context` and `include_examples` support a block, which gets eval'd
in the current context (vs the nested context generated by `it_behaves_like`).
* Add `config.order = 'random'` to the `spec_helper.rb` generated by `rspec
--init`.
* Delay the loading of DRb (Myron Marston).
* Limit monkey patching of `describe` onto just the objects that need it rather
than every object in the system (Myron Marston).
Bug fixes
* Support alternative path separators. For example, on Windows, you can now do
this: `rspec spec\subdir`. (Jarmo Pertman @jarmo)
* When an example raises an error and an after or around hook does as
well, print out the hook error. Previously, the error was silenced and
the user got no feedback about what happened. (Myron Marston)
* `--require` and `-I` are merged among different configuration sources (Andy
Lindeman)
* Delegate to mocha methods instead of aliasing them in mocha adapter.
### 2.10.1 / 2012-05-19
[full changelog](http://github.com/rspec/rspec-core/compare/v2.10.0...v2.10.1)
Bug fixes
* `RSpec.reset` properly reinits configuration and world
* Call `to_s` before `split` on exception messages that might not always be
Strings (slyphon)
### 2.10.0 / 2012-05-03
[full changelog](http://github.com/rspec/rspec-core/compare/v2.9.0...v2.10.0)
Enhancements
* Add `prepend_before` and `append_after` hooks (preethiramdev)
* intended for extension libs
* restores rspec-1 behavior
* Reporting of profiled examples (moro)
* Report the total amount of time taken for the top slowest examples.
* Report what percentage the slowest examples took from the total runtime.
Bug fixes
* Properly parse `SPEC_OPTS` options.
* `example.description` returns the location of the example if there is no
explicit description or matcher-generated description.
* RDoc fixes (Grzegorz Świrski)
* Do not modify example ancestry when dumping errors (Michael Grosser)
### 2.9.0 / 2012-03-17
[full changelog](http://github.com/rspec/rspec-core/compare/v2.8.0...v2.9.0)
Enhancements
* Support for "X minutes X seconds" spec run duration in formatter. (uzzz)
* Strip whitespace from group and example names in doc formatter.
* Removed spork-0.9 shim. If you're using spork-0.8.x, you'll need to upgrade
to 0.9.0.
Bug fixes
* Restore `--full_backtrace` option
* Ensure that values passed to `config.filter_run` are respected when running
over DRb (using spork).
* Ensure shared example groups are reset after a run (as example groups are).
* Remove `rescue false` from calls to filters represented as Procs
* Ensure `described_class` gets the closest constant (pyromaniac)
* In "autorun", don't run the specs in the `at_exit` hook if there was an
exception (most likely due to a SyntaxError). (sunaku)
* Don't extend groups with modules already used to extend ancestor groups.
* `its` correctly memoizes nil or false values (Yamada Masaki)
### 2.8.0 / 2012-01-04
[full changelog](http://github.com/rspec/rspec-core/compare/v2.8.0.rc2...v2.8.0)
Bug fixes
* For metadata filtering, restore passing the entire array to the proc, rather
than each item in the array (weidenfreak)
* Ensure each spec file is loaded only once
* Fixes a bug that caused all the examples in a file to be run when
referenced twice with line numbers in a command, e.g.
* `rspec path/to/file:37 path/to/file:42`
### 2.8.0.rc2 / 2011-12-19
[full changelog](http://github.com/rspec/rspec-core/compare/v2.8.0.rc1...v2.8.0.rc2)
Enhancments
* new `--init` command (Peter Schröder)
* generates `spec/spec_helper.rb`
* deletes obsolete files (on confirmation)
* merged with and deprecates `--configure` command, which generated
`.rspec`
* use `require_relative` when available (Ian Leitch)
* `include_context` and `include_examples` accept params (Calvin Bascom)
* print the time for every example in the html formatter (Richie Vos)
* several tasty refactoring niblets (Sasha)
* `it "does something", :x => [:foo,'bar',/baz/] (Ivan Neverov)
* supports matching n command line tag values with an example or group
### 2.8.0.rc1 / 2011-11-06
[full changelog](http://github.com/rspec/rspec-core/compare/v2.7.1...v2.8.0.rc1)
Enhancements
* `--order` (Justin Ko)
* run examples in random order: `--order rand`
* specify the seed: `--order rand:123`
* `--seed SEED`
* equivalent of `--order rand:SEED`
* SharedContext supports `let` (David Chelimsky)
* Filter improvements (David Chelimsky)
* override opposing tags from the command line
* override RSpec.configure tags from the command line
* `--line_number 37` overrides all other filters
* `path/to/file.rb:37` overrides all other filters
* refactor: consolidate filter management in a FilterManger object
* Eliminate Ruby warnings (Matijs van Zuijlen)
* Make reporter.report an API (David Chelimsky)
* supports extension tools like interative_rspec
Changes
* change `config.color_enabled` (getter/setter/predicate) to `color` to align
with `--[no]-color` CLI option.
* `color_enabled` is still supported for now, but will likley be deprecated
in a 2.x release so we can remove it in 3.0.
Bug fixes
* Make sure the `bar` in `--tag foo:bar` makes it to DRb (Aaron Gibralter)
* Fix bug where full descriptions of groups nested 3 deep were repeated.
* Restore report of time to run to start after files are loaded.
* fixes bug where run times were cumalitive in spork
* fixes compatibility with time-series metrics
* Don't error out when `config.mock_with` or `expect_with` is re-specifying the
current config (Myron Marston)
* Deprecations
* :alias option on `configuration.add_setting`. Use `:alias_with` on the
original setting declaration instead.
### 2.7.1 / 2011-10-20
[full changelog](http://github.com/rspec/rspec-core/compare/v2.7.0...v2.7.1)
Bug fixes
* tell autotest the correct place to find the rspec executable
### 2.7.0 / 2011-10-16
[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.4...v2.7.0)
NOTE: RSpec's release policy dictates that there should not be any backward
incompatible changes in minor releases, but we're making an exception to
release a change to how RSpec interacts with other command line tools.
As of 2.7.0, you must explicity `require "rspec/autorun"` unless you use the
`rspec` command (which already does this for you).
Enhancements
* Add `example.exception` (David Chelimsky)
* `--default_path` command line option (Justin Ko)
* support multiple `--line_number` options (David J. Hamilton)
* also supports `path/to/file.rb:5:9` (runs examples on lines 5 and 9)
* Allow classes/modules to be used as shared example group identifiers (Arthur
Gunn)
* Friendly error message when shared context cannot be found (Sławosz
Sławiński)
* Clear formatters when resetting config (John Bintz)
* Add `xspecify` and xexample as temp-pending methods (David Chelimsky)
* Add `--no-drb` option (Iain Hecker)
* Provide more accurate run time by registering start time before code is
loaded (David Chelimsky)
* reverted in 2.8.0
* Rake task default pattern finds specs in symlinked dirs (Kelly Felkins)
* Rake task no longer does anything to invoke bundler since Bundler already
handles it for us. Thanks to Andre Arko for the tip.
* Add `--failure-exit-code` option (Chris Griego)
Bug fixes
* Include `Rake::DSL` to remove deprecation warnings in Rake > 0.8.7 (Pivotal
Casebook)
* Only eval `let` block once even if it returns `nil` (Adam Meehan)
* Fix `--pattern` option (wasn't being recognized) (David Chelimsky)
* Only implicitly `require "rspec/autorun"` with the `rspec` command (David
Chelimsky)
* Ensure that rspec's `at_exit` defines the exit code (Daniel Doubrovkine)
* Show the correct snippet in the HTML and TextMate formatters (Brian Faherty)
### 2.6.4 / 2011-06-06
[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.3...v2.6.4)
NOTE: RSpec's release policy dictates that there should not be new
functionality in patch releases, but this minor enhancement slipped in by
accident. As it doesn't add a new API, we decided to leave it in rather than
roll back this release.
Enhancements
* Add summary of commands to run individual failed examples.
Bug fixes
* Support exclusion filters in DRb. (Yann Lugrin)
* Fix --example escaping when run over DRb. (Elliot Winkler)
* Use standard ANSI codes for color formatting so colors work in a wider set of
color schemes.
### 2.6.3 / 2011-05-24
[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.2...v2.6.3)
Bug fixes
* Explicitly convert exit code to integer, avoiding TypeError when return
value of run is IO object proxied by `DRb::DRbObject` (Julian Scheid)
* Clarify behavior of `--example` command line option
* Build using a rubygems-1.6.2 to avoid downstream yaml parsing error
### 2.6.2 / 2011-05-21
[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.1...v2.6.2)
Bug fixes
* Warn rather than raise when HOME env var is not defined
* Properly merge command-line exclusions with default :if and :unless (joshcooper)
### 2.6.1 / 2011-05-19
[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.0...v2.6.1)
Bug fixes
* Don't extend nil when filters are nil
* `require 'rspec/autorun'` when running rcov.
### 2.6.0 / 2011-05-12
[full changelog](http://github.com/rspec/rspec-core/compare/v2.5.1...v2.6.0)
Enhancements
* `shared_context` (Damian Nurzynski)
* extend groups matching specific metadata with:
* method definitions
* subject declarations
* let/let! declarations
* etc (anything you can do in a group)
* `its([:key])` works for any subject with #[]. (Peter Jaros)
* `treat_symbols_as_metadata_keys_with_true_values` (Myron Marston)
* Print a deprecation warning when you configure RSpec after defining an
example. All configuration should happen before any examples are defined.
(Myron Marston)
* Pass the exit status of a DRb run to the invoking process. This causes specs
run via DRb to not just return true or false. (Ilkka Laukkanen)
* Refactoring of `ConfigurationOptions#parse_options` (Rodrigo Rosenfeld Rosas)
* Report excluded filters in runner output (tip from andyl)
* Clean up messages for filters/tags.
* Restore --pattern/-P command line option from rspec-1
* Support false as well as true in config.full_backtrace= (Andreas Tolf
Tolfsen)
Bug fixes
* Don't stumble over an exception without a message (Hans Hasselberg)
* Remove non-ascii characters from comments that were choking rcov (Geoffrey
Byers)
* Fixed backtrace so it doesn't include lines from before the autorun at_exit
hook (Myron Marston)
* Include RSpec::Matchers when first example group is defined, rather than just
before running the examples. This works around an obscure bug in ruby 1.9
that can cause infinite recursion. (Myron Marston)
* Don't send `example_group_[started|finished]` to formatters for empty groups.
* Get specs passing on jruby (Sidu Ponnappa)
* Fix bug where mixing nested groups and outer-level examples gave
unpredictable :line_number behavior (Artur Małecki)
* Regexp.escape the argument to --example (tip from Elliot Winkler)
* Correctly pass/fail pending block with message expectations
* CommandLine returns exit status (0/1) instead of true/false
* Create path to formatter output file if it doesn't exist (marekj).
### 2.5.1 / 2011-02-06
[full changelog](http://github.com/rspec/rspec-core/compare/v2.5.0...v2.5.1)
NOTE: this release breaks compatibility with rspec/autotest/bundler
integration, but does so in order to greatly simplify it.
With this release, if you want the generated autotest command to include
'bundle exec', require Autotest's bundler plugin in a .autotest file in the
project's root directory or in your home directory:
require "autotest/bundler"
Now you can just type 'autotest' on the commmand line and it will work as you expect.
If you don't want 'bundle exec', there is nothing you have to do.
### 2.5.0 / 2011-02-05
[full changelog](http://github.com/rspec/rspec-core/compare/v2.4.0...v2.5.0)
Enhancements
* Autotest::Rspec2 parses command line args passed to autotest after '--'
* --skip-bundler option for autotest command
* Autotest regexp fixes (Jon Rowe)
* Add filters to html and textmate formatters (Daniel Quimper)
* Explicit passing of block (need for JRuby 1.6) (John Firebaugh)
Bug fixes
* fix dom IDs in HTML formatter (Brian Faherty)
* fix bug with --drb + formatters when not running in drb
* include --tag options in drb args (monocle)
* fix regression so now SPEC_OPTS take precedence over CLI options again (Roman
Chernyatchik)
* only call its(:attribute) once (failing example from Brian Dunn)
* fix bizarre bug where rspec would hang after String.alias :to_int :to_i
(Damian Nurzynski)
Deprecations
* implicit inclusion of 'bundle exec' when Gemfile present (use autotest's
bundler plugin instead)
### 2.4.0 / 2011-01-02
[full changelog](http://github.com/rspec/rspec-core/compare/v2.3.1...v2.4.0)
Enhancements
* start the debugger on -d so the stack trace is visible when it stops
(Clifford Heath)
* apply hook filtering to examples as well as groups (Myron Marston)
* support multiple formatters, each with their own output
* show exception classes in failure messages unless they come from RSpec
matchers or message expectations
* before(:all) { pending } sets all examples to pending
Bug fixes
* fix bug due to change in behavior of reject in Ruby 1.9.3-dev (Shota
Fukumori)
* fix bug when running in jruby: be explicit about passing block to super (John
Firebaugh)
* rake task doesn't choke on paths with quotes (Janmejay Singh)
* restore --options option from rspec-1
* require 'ostruct' to fix bug with its([key]) (Kim Burgestrand)
* --configure option generates .rspec file instead of autotest/discover.rb
### 2.3.1 / 2010-12-16
[full changelog](http://github.com/rspec/rspec-core/compare/v2.3.0...v2.3.1)
Bug fixes
* send debugger warning message to $stdout if RSpec.configuration.error_stream
has not been defined yet.
* HTML Formatter _finally_ properly displays nested groups (Jarmo Pertman)
* eliminate some warnings when running RSpec's own suite (Jarmo Pertman)
### 2.3.0 / 2010-12-12
[full changelog](http://github.com/rspec/rspec-core/compare/v2.2.1...v2.3.0)
Enhancements
* tell autotest to use "rspec2" if it sees a .rspec file in the project's root
directory
* replaces the need for ./autotest/discover.rb, which will not work with
all versions of ZenTest and/or autotest
* config.expect_with
* :rspec # => rspec/expectations
* :stdlib # => test/unit/assertions
* :rspec, :stdlib # => both
Bug fixes
* fix dev Gemfile to work on non-mac-os machines (Lake Denman)
* ensure explicit subject is only eval'd once (Laszlo Bacsi)
### 2.2.1 / 2010-11-28
[full changelog](http://github.com/rspec/rspec-core/compare/v2.2.0...v2.2.1)
Bug fixes
* alias_method instead of override Kernel#method_missing (John Wilger)
* changed --autotest to --tty in generated command (MIKAMI Yoshiyuki)
* revert change to debugger (had introduced conflict with Rails)
* also restored --debugger/-debug option
### 2.2.0 / 2010-11-28
[full changelog](http://github.com/rspec/rspec-core/compare/v2.1.0...v2.2.0)
Deprecations/changes
* --debug/-d on command line is deprecated and now has no effect
* win32console is now ignored; Windows users must use ANSICON for color support
(Bosko Ivanisevic)
Enhancements
* When developing locally rspec-core now works with the rspec-dev setup or your
local gems
* Raise exception with helpful message when rspec-1 is loaded alongside rspec-2
(Justin Ko)
* debugger statements _just work_ as long as ruby-debug is installed
* otherwise you get warned, but not fired
* Expose example.metadata in around hooks
* Performance improvments (much faster now)
Bug fixes
* Make sure --fail-fast makes it across drb
* Pass -Ilib:spec to rcov
### 2.1.0 / 2010-11-07
[full changelog](http://github.com/rspec/rspec-core/compare/v2.0.1...v2.1.0)
Enhancments
* Add skip_bundler option to rake task to tell rake task to ignore the presence
of a Gemfile (jfelchner)
* Add gemfile option to rake task to tell rake task what Gemfile to look for
(defaults to 'Gemfile')
* Allow passing caller trace into Metadata to support extensions (Glenn
Vanderburg)
* Add deprecation warning for Spec::Runner.configure to aid upgrade from
RSpec-1
* Add deprecated Spec::Rake::SpecTask to aid upgrade from RSpec-1
* Add 'autospec' command with helpful message to aid upgrade from RSpec-1
* Add support for filtering with tags on CLI (Lailson Bandeira)
* Add a helpful message about RUBYOPT when require fails in bin/rspec (slyphon)
* Add "-Ilib" to the default rcov options (Tianyi Cui)
* Make the expectation framework configurable (default rspec, of course)
(Justin Ko)
* Add 'pending' to be conditional (Myron Marston)
* Add explicit support for :if and :unless as metadata keys for conditional run
of examples (Myron Marston)
* Add --fail-fast command line option (Jeff Kreeftmeijer)
Bug fixes
* Eliminate stack overflow with "subject { self }"
* Require 'rspec/core' in the Raketask (ensures it required when running rcov)
### 2.0.1 / 2010-10-18
[full changelog](http://github.com/rspec/rspec-core/compare/v2.0.0...v2.0.1)
Bug fixes
* Restore color when using spork + autotest
* Pending examples without docstrings render the correct message (Josep M.
Bach)
* Fixed bug where a failure in a spec file ending in anything but _spec.rb
would fail in a confusing way.
* Support backtrace lines from erb templates in html formatter (Alex Crichton)
### 2.0.0 / 2010-10-10
[full changelog](http://github.com/rspec/rspec-core/compare/v2.0.0.rc...v2.0.0)
RSpec-1 compatibility
* Rake task uses ENV["SPEC"] as file list if present
Bug fixes
* Bug Fix: optparse --out foo.txt (Leonardo Bessa)
* Suppress color codes for non-tty output (except autotest)
### 2.0.0.rc / 2010-10-05
[full changelog](http://github.com/rspec/rspec-core/compare/v2.0.0.beta.22...v2.0.0.rc)
Enhancements
* implicitly require unknown formatters so you don't have to require the file
explicitly on the commmand line (Michael Grosser)
* add --out/-o option to assign output target
* added fail_fast configuration option to abort on first failure
* support a Hash subject (its([:key]) { should == value }) (Josep M. Bach)
Bug fixes
* Explicitly require rspec version to fix broken rdoc task (Hans de Graaff)
* Ignore backtrace lines that come from other languages, like Java or
Javascript (Charles Lowell)
* Rake task now does what is expected when setting (or not setting)
fail_on_error and verbose
* Fix bug in which before/after(:all) hooks were running on excluded nested
groups (Myron Marston)
* Fix before(:all) error handling so that it fails examples in nested groups,
too (Myron Marston)
### 2.0.0.beta.22 / 2010-09-12
[full changelog](http://github.com/rspec/rspec-core/compare/v2.0.0.beta.20...v2.0.0.beta.22)
Enhancements
* removed at_exit hook
* CTRL-C stops the run (almost) immediately
* first it cleans things up by running the appropriate after(:all) and
after(:suite) hooks
* then it reports on any examples that have already run
* cleaned up rake task
* generate correct task under variety of conditions
* options are more consistent
* deprecated redundant options
* run 'bundle exec autotest' when Gemfile is present
* support ERB in .rspec options files (Justin Ko)
* depend on bundler for development tasks (Myron Marston)
* add example_group_finished to formatters and reporter (Roman Chernyatchik)
Bug fixes
* support paths with spaces when using autotest (Andreas Neuhaus)
* fix module_exec with ruby 1.8.6 (Myron Marston)
* remove context method from top-level
* was conflicting with irb, for example
* errors in before(:all) are now reported correctly (Chad Humphries)
Removals
* removed -o --options-file command line option
* use ./.rspec and ~/.rspec
rspec-core-2.14.7/spec/ 0000755 0000041 0000041 00000000000 12261207027 014630 5 ustar www-data www-data rspec-core-2.14.7/spec/spec_helper.rb 0000644 0000041 0000041 00000005620 12261207027 017451 0 ustar www-data www-data require 'rubygems'
begin
require 'spork'
rescue LoadError
module Spork
def self.prefork
yield
end
def self.each_run
yield
end
end
end
Spork.prefork do
require 'rspec/autorun'
require 'autotest/rspec2'
require 'aruba/api'
if RUBY_PLATFORM == 'java'
# Works around https://jira.codehaus.org/browse/JRUBY-5678
require 'fileutils'
ENV['TMPDIR'] = File.expand_path('../../tmp', __FILE__)
FileUtils.mkdir_p(ENV['TMPDIR'])
end
Dir['./spec/support/**/*.rb'].map {|f| require f}
class NullObject
private
def method_missing(method, *args, &block)
# ignore
end
end
module Sandboxing
def self.sandboxed(&block)
@orig_config = RSpec.configuration
@orig_world = RSpec.world
new_config = RSpec::Core::Configuration.new
new_world = RSpec::Core::World.new(new_config)
RSpec.configuration = new_config
RSpec.world = new_world
object = Object.new
object.extend(RSpec::Core::SharedExampleGroup)
(class << RSpec::Core::ExampleGroup; self; end).class_eval do
alias_method :orig_run, :run
def run(reporter=nil)
orig_run(reporter || NullObject.new)
end
end
RSpec::Core::SandboxedMockSpace.sandboxed do
object.instance_eval(&block)
end
ensure
(class << RSpec::Core::ExampleGroup; self; end).class_eval do
remove_method :run
alias_method :run, :orig_run
remove_method :orig_run
end
RSpec.configuration = @orig_config
RSpec.world = @orig_world
end
end
def in_editor?
ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM')
end
module EnvHelpers
def with_env_vars(vars)
original = ENV.to_hash
vars.each { |k, v| ENV[k] = v }
begin
yield
ensure
ENV.replace(original)
end
end
def without_env_vars(*vars)
original = ENV.to_hash
vars.each { |k| ENV.delete(k) }
begin
yield
ensure
ENV.replace(original)
end
end
end
RSpec.configure do |c|
# structural
c.alias_it_behaves_like_to 'it_has_behavior'
c.around {|example| Sandboxing.sandboxed { example.run }}
c.include(RSpecHelpers)
c.include Aruba::Api, :example_group => {
:file_path => /spec\/command_line/
}
c.expect_with :rspec do |expectations|
expectations.syntax = :expect
end
# runtime options
c.treat_symbols_as_metadata_keys_with_true_values = true
c.color = !in_editor?
c.filter_run :focus
c.include EnvHelpers
c.run_all_when_everything_filtered = true
c.filter_run_excluding :ruby => lambda {|version|
case version.to_s
when "!jruby"
RUBY_ENGINE == "jruby"
when /^> (.*)/
!(RUBY_VERSION.to_s > $1)
else
!(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
end
}
end
end
Spork.each_run do
end
rspec-core-2.14.7/spec/autotest/ 0000755 0000041 0000041 00000000000 12261207027 016500 5 ustar www-data www-data rspec-core-2.14.7/spec/autotest/failed_results_re_spec.rb 0000644 0000041 0000041 00000002367 12261207027 023542 0 ustar www-data www-data require "spec_helper"
describe "failed_results_re for autotest" do
def run_example
group = RSpec::Core::ExampleGroup.describe("group")
group.example("example") { yield }
io = StringIO.new
formatter = RSpec::Core::Formatters::BaseTextFormatter.new(io)
reporter = RSpec::Core::Reporter.new(formatter)
group.run(reporter)
reporter.report(1, nil) {}
io.string
end
shared_examples "autotest failed_results_re" do
it "matches a failure" do
output = run_example { fail }
expect(output).to match(Autotest::Rspec2.new.failed_results_re)
expect(output).to include(__FILE__.sub(File.expand_path('.'),'.'))
end
it "does not match when there are no failures" do
output = run_example { } # pass
expect(output).not_to match(Autotest::Rspec2.new.failed_results_re)
expect(output).not_to include(__FILE__.sub(File.expand_path('.'),'.'))
end
end
context "with color enabled" do
before do
RSpec.configuration.stub(:color_enabled? => true)
end
include_examples "autotest failed_results_re"
end
context "with color disabled " do
before do
RSpec.configuration.stub(:color_enabled? => false)
end
include_examples "autotest failed_results_re"
end
end
rspec-core-2.14.7/spec/autotest/rspec_spec.rb 0000644 0000041 0000041 00000010345 12261207027 021156 0 ustar www-data www-data require "spec_helper"
describe Autotest::Rspec2 do
let(:rspec_autotest) { Autotest::Rspec2.new }
let(:spec_cmd) { File.expand_path("../../../exe/rspec", __FILE__) }
let(:ruby_cmd) { "/path/to/ruby" }
before do
File.stub(:exist?) { false }
end
it "uses autotest's prefix" do
rspec_autotest.prefix = "this is the prefix "
expect(rspec_autotest.make_test_cmd({'a' => 'b'})).to match(/this is the prefix/)
end
describe "commands" do
before do
rspec_autotest.stub(:ruby => ruby_cmd)
files = %w[file_one file_two]
@files_to_test = {
files[0] => [],
files[1] => []
}
# this is not the inner representation of Autotest!
rspec_autotest.files_to_test = @files_to_test
@to_test = files.map { |f| File.expand_path(f) }.join ' '
end
it "uses double quotes for windows compatibility" do
command = rspec_autotest.make_test_cmd(@files_to_test)
expect(command).to include('"')
expect(command).not_to include("'")
end
it "makes the appropriate test command" do
actual_command = rspec_autotest.make_test_cmd(@files_to_test)
expected_command = /#{ruby_cmd}.*"#{spec_cmd}" (.*)/
expect(actual_command).to match(expected_command)
actual_command =~ expected_command
expect($1).to match(/#{File.expand_path('file_one')}/)
expect($1).to match(/#{File.expand_path('file_two')}/)
end
it "returns a blank command for no files" do
expect(rspec_autotest.make_test_cmd({})).to eq('')
end
it "quotes the paths of files to test" do
cmd = rspec_autotest.make_test_cmd(@files_to_test)
@files_to_test.keys.each do |file_to_test|
expect(cmd).to match(/"#{File.expand_path(file_to_test)}"/)
end
end
it "quotes the path of the ruby executable" do
cmd = rspec_autotest.make_test_cmd(@files_to_test)
expect(cmd).to match(%r("/path/to/ruby"))
end
it "gives '--tty' to #{Autotest::Rspec2::RSPEC_EXECUTABLE}, not '--autotest'" do
cmd = rspec_autotest.make_test_cmd(@files_to_test)
expect(cmd).to match(' --tty ')
expect(cmd).not_to match(' --autotest ')
end
end
describe "mappings" do
before do
@lib_file = "lib/something.rb"
@spec_file = "spec/something_spec.rb"
rspec_autotest.hook :initialize
end
it "finds the spec file for a given lib file" do
expect(rspec_autotest).to map_specs([@spec_file]).to(@lib_file)
end
it "finds the spec file if given a spec file" do
expect(rspec_autotest).to map_specs([@spec_file]).to(@spec_file)
end
it "ignores files in spec dir that aren't specs" do
expect(rspec_autotest).to map_specs([]).to("spec/spec_helper.rb")
end
it "ignores untracked files (in @file)" do
expect(rspec_autotest).to map_specs([]).to("lib/untracked_file")
end
end
describe "consolidating failures" do
let(:subject_file) { "lib/autotest/some.rb" }
let(:spec_file) { "spec/autotest/some_spec.rb" }
it "returns no failures if no failures were given in the output" do
expect(rspec_autotest.consolidate_failures([[]])).to eq({})
end
it "returns a hash with the spec filename => spec name for each failure or error" do
failures = [ [ "false should be false", spec_file ] ]
expect(rspec_autotest.consolidate_failures(failures)).to eq({
spec_file => ["false should be false"]
})
end
context "when subject file appears before the spec file in the backtrace" do
let(:failures) do
[ [ "false should be false", "#{subject_file}:143:\n#{spec_file}:203:" ] ]
end
it "excludes the subject file" do
expect(rspec_autotest.consolidate_failures(failures).keys).not_to include(subject_file)
end
it "includes the spec file" do
expect(rspec_autotest.consolidate_failures(failures).keys).to include(spec_file)
end
end
end
describe "normalizing file names" do
it "ensures that a single file appears in files_to_test only once" do
@files_to_test = {}
['filename.rb', './filename.rb', File.expand_path('filename.rb')].each do |file|
@files_to_test[file] = []
end
expect(rspec_autotest.normalize(@files_to_test)).to have(1).file
end
end
end
rspec-core-2.14.7/spec/autotest/discover_spec.rb 0000644 0000041 0000041 00000001142 12261207027 021653 0 ustar www-data www-data require "spec_helper"
describe "autotest/discover.rb" do
context "with ./.rspec present" do
it "adds 'rspec2' to the list of discoveries" do
File.stub(:exist?).with("./.rspec") { true }
Autotest.should_receive(:add_discovery)
load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
end
end
context "with ./.rspec absent" do
it "does not add 'rspec2' to the list of discoveries" do
File.stub(:exist?) { false }
Autotest.should_not_receive(:add_discovery)
load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
end
end
end
rspec-core-2.14.7/spec/command_line/ 0000755 0000041 0000041 00000000000 12261207027 017255 5 ustar www-data www-data rspec-core-2.14.7/spec/command_line/order_spec.rb 0000644 0000041 0000041 00000016520 12261207027 021733 0 ustar www-data www-data require 'spec_helper'
describe 'command line', :ui do
let(:stderr) { StringIO.new }
let(:stdout) { StringIO.new }
before :all do
write_file 'spec/simple_spec.rb', """
describe 'group 1' do
specify('group 1 example 1') {}
specify('group 1 example 2') {}
specify('group 1 example 3') {}
describe 'group 1-1' do
specify('group 1-1 example 1') {}
specify('group 1-1 example 2') {}
specify('group 1-1 example 3') {}
end
end
"""
write_file 'spec/simple_spec2.rb', """
describe 'group 2' do
specify('group 2 example 1') {}
specify('group 2 example 2') {}
specify('group 2 example 3') {}
describe 'group 2-1' do
specify('group 2-1 example 1') {}
specify('group 2-1 example 2') {}
specify('group 2-1 example 3') {}
end
end
"""
write_file 'spec/order_spec.rb', """
describe 'group 1' do
specify('group 1 example 1') {}
specify('group 1 example 2') {}
specify('group 1 example 3') {}
specify('group 1 example 4') {}
specify('group 1 example 5') {}
specify('group 1 example 6') {}
specify('group 1 example 5') {}
specify('group 1 example 7') {}
specify('group 1 example 8') {}
specify('group 1 example 9') {}
specify('group 1 example 10') {}
describe 'group 1-1' do
specify('group 1-1 example 1') {}
specify('group 1-1 example 2') {}
specify('group 1-1 example 3') {}
specify('group 1-1 example 4') {}
specify('group 1-1 example 5') {}
specify('group 1-1 example 6') {}
specify('group 1-1 example 7') {}
specify('group 1-1 example 8') {}
specify('group 1-1 example 9') {}
specify('group 1-1 example 10') {}
end
describe('group 1-2') { specify('example') {} }
describe('group 1-3') { specify('example') {} }
describe('group 1-4') { specify('example') {} }
describe('group 1-5') { specify('example') {} }
describe('group 1-6') { specify('example') {} }
describe('group 1-7') { specify('example') {} }
describe('group 1-8') { specify('example') {} }
describe('group 1-9') { specify('example') {} }
describe('group 1-10') { specify('example') {} }
end
describe('group 2') { specify('example') {} }
describe('group 3') { specify('example') {} }
describe('group 4') { specify('example') {} }
describe('group 5') { specify('example') {} }
describe('group 6') { specify('example') {} }
describe('group 7') { specify('example') {} }
describe('group 8') { specify('example') {} }
describe('group 9') { specify('example') {} }
describe('group 10') { specify('example') {} }
"""
end
describe '--order rand' do
it 'runs the examples and groups in a different order each time' do
run_command 'tmp/aruba/spec/order_spec.rb --order rand -f doc'
RSpec.configuration.seed = srand && srand # reset seed in same process
run_command 'tmp/aruba/spec/order_spec.rb --order rand -f doc'
expect(stdout.string).to match(/Randomized with seed \d+/)
top_level_groups {|first_run, second_run| expect(first_run).to_not eq(second_run)}
nested_groups {|first_run, second_run| expect(first_run).to_not eq(second_run)}
examples('group 1') {|first_run, second_run| expect(first_run).to_not eq(second_run)}
examples('group 1-1') {|first_run, second_run| expect(first_run).to_not eq(second_run)}
end
end
describe '--order rand:SEED' do
it 'runs the examples and groups in the same order each time' do
2.times { run_command 'tmp/aruba/spec/order_spec.rb --order rand:123 -f doc' }
expect(stdout.string).to match(/Randomized with seed 123/)
top_level_groups {|first_run, second_run| expect(first_run).to eq(second_run)}
nested_groups {|first_run, second_run| expect(first_run).to eq(second_run)}
examples('group 1') {|first_run, second_run| expect(first_run).to eq(second_run)}
examples('group 1-1') {|first_run, second_run| expect(first_run).to eq(second_run)}
end
end
describe '--seed SEED' do
it "forces '--order rand' and runs the examples and groups in the same order each time" do
2.times { run_command 'tmp/aruba/spec/order_spec.rb --seed 123 -f doc' }
expect(stdout.string).to match(/Randomized with seed \d+/)
top_level_groups {|first_run, second_run| expect(first_run).to eq(second_run)}
nested_groups {|first_run, second_run| expect(first_run).to eq(second_run)}
examples('group 1') {|first_run, second_run| expect(first_run).to eq(second_run)}
examples('group 1-1') {|first_run, second_run| expect(first_run).to eq(second_run)}
end
it "runs examples in the same order, regardless of the order in which files are given" do
run_command 'tmp/aruba/spec/simple_spec.rb tmp/aruba/spec/simple_spec2.rb --seed 1337 -f doc'
run_command 'tmp/aruba/spec/simple_spec2.rb tmp/aruba/spec/simple_spec.rb --seed 1337 -f doc'
top_level_groups {|first_run, second_run| expect(first_run).to eq(second_run)}
nested_groups {|first_run, second_run| expect(first_run).to eq(second_run)}
end
end
describe '--order default on CLI with --order rand in .rspec' do
it "overrides --order rand with --order default" do
write_file '.rspec', '--order rand'
run_command 'tmp/aruba/spec/order_spec.rb --order default -f doc'
expect(stdout.string).not_to match(/Randomized/)
expect(stdout.string).to match(
/group 1.*group 1 example 1.*group 1 example 2.*group 1-1.*group 1-2.*group 2.*/m
)
end
end
context 'when a custom order is configured' do
before do
write_file 'spec/custom_order_spec.rb', """
RSpec.configure do |config|
config.order_groups_and_examples do |list|
list.sort_by { |item| item.description }
end
end
describe 'group B' do
specify('group B example D') {}
specify('group B example B') {}
specify('group B example A') {}
specify('group B example C') {}
end
describe 'group A' do
specify('group A example 1') {}
end
"""
end
it 'orders the groups and examples by the provided strategy' do
run_command 'tmp/aruba/spec/custom_order_spec.rb -f doc'
top_level_groups { |groups| expect(groups.flatten).to eq(['group A', 'group B']) }
examples('group B') do |examples|
letters = examples.flatten.map { |e| e[/(.)\z/, 1] }
expect(letters).to eq(['A', 'B', 'C', 'D'])
end
end
end
def examples(group)
yield split_in_half(stdout.string.scan(/^\s+#{group} example.*$/))
end
def top_level_groups
yield example_groups_at_level(0)
end
def nested_groups
yield example_groups_at_level(2)
end
def example_groups_at_level(level)
split_in_half(stdout.string.scan(/^\s{#{level*2}}group.*$/))
end
def split_in_half(array)
length, midpoint = array.length, array.length / 2
return array.slice(0, midpoint), array.slice(midpoint, length)
end
def run_command(cmd)
RSpec::Core::Runner.run(cmd.split, stderr, stdout)
end
end
rspec-core-2.14.7/spec/rspec/ 0000755 0000041 0000041 00000000000 12261207027 015744 5 ustar www-data www-data rspec-core-2.14.7/spec/rspec/core/ 0000755 0000041 0000041 00000000000 12261207027 016674 5 ustar www-data www-data rspec-core-2.14.7/spec/rspec/core/rspec_matchers_spec.rb 0000644 0000041 0000041 00000002757 12261207027 023250 0 ustar www-data www-data require 'spec_helper'
module RSpec::Matchers
def __method_with_super
super
end
module ModThatIncludesMatchers
include RSpec::Matchers
end
RSpec.configure do |c|
c.include RSpec::Matchers, :include_rspec_matchers => true
c.include ModThatIncludesMatchers, :include_mod_that_includes_rspec_matchers => true
end
describe self do
shared_examples_for "a normal module with a method that supers" do
it "raises the expected error (and not SystemStackError)" do
expect { __method_with_super }.to raise_error(NoMethodError) # there is no __method_with_super in an ancestor
end
end
it_behaves_like "a normal module with a method that supers"
context "when RSpec::Matchers has been included in an example group" do
include RSpec::Matchers
it_behaves_like "a normal module with a method that supers"
end
context "when a module that includes RSpec::Matchers has been included in an example group" do
include RSpec::Matchers::ModThatIncludesMatchers
it_behaves_like "a normal module with a method that supers"
end
context "when RSpec::Matchers is included via configuration", :include_rspec_matchers => true do
it_behaves_like "a normal module with a method that supers"
end
context "when RSpec::Matchers is included in a module that is included via configuration", :include_mod_that_includes_rspec_matchers => true do
it_behaves_like "a normal module with a method that supers"
end
end
end
rspec-core-2.14.7/spec/rspec/core/project_initializer_spec.rb 0000644 0000041 0000041 00000010170 12261207027 024303 0 ustar www-data www-data require "spec_helper"
module RSpec::Core
describe ProjectInitializer, :isolated_directory => true do
describe "#run" do
context "with no args" do
let(:command_line_config) { ProjectInitializer.new }
before do
command_line_config.stub(:warn)
command_line_config.stub(:puts)
command_line_config.stub(:gets => 'no')
end
context "with no .rspec file" do
it "says it's creating .rspec " do
command_line_config.should_receive(:puts).with(/create\s+\.rspec/)
command_line_config.run
end
it "generates a .rspec" do
command_line_config.run
expect(File.read('.rspec')).to match(/--color\n--format progress/m)
end
end
context "with a .rspec file" do
it "says .rspec exists" do
FileUtils.touch('.rspec')
command_line_config.should_receive(:puts).with(/exist\s+\.rspec/)
command_line_config.run
end
it "doesn't create a new one" do
File.open('.rspec', 'w') {|f| f << '--color'}
command_line_config.run
expect(File.read('.rspec')).to eq('--color')
end
end
context "with no spec/spec_helper.rb file" do
it "says it's creating spec/spec_helper.rb " do
command_line_config.should_receive(:puts).with(/create\s+spec\/spec_helper.rb/)
command_line_config.run
end
it "generates a spec/spec_helper.rb" do
command_line_config.run
expect(File.read('spec/spec_helper.rb')).to match(/RSpec\.configure do \|config\|/m)
end
end
context "with a spec/spec_helper.rb file" do
before { FileUtils.mkdir('spec') }
it "says spec/spec_helper.rb exists" do
FileUtils.touch('spec/spec_helper.rb')
command_line_config.should_receive(:puts).with(/exist\s+spec\/spec_helper.rb/)
command_line_config.run
end
it "doesn't create a new one" do
random_content = "content #{rand}"
File.open('spec/spec_helper.rb', 'w') {|f| f << random_content}
command_line_config.run
expect(File.read('spec/spec_helper.rb')).to eq(random_content)
end
end
context "with autotest/discover.rb" do
before do
FileUtils.mkdir('autotest')
FileUtils.touch 'autotest/discover.rb'
end
it "asks whether to delete the file" do
command_line_config.should_receive(:puts).with(/delete/)
command_line_config.run
end
it "removes it if confirmed" do
command_line_config.stub(:gets => 'yes')
command_line_config.run
expect(File.exist?('autotest/discover.rb')).to be_false
end
it "leaves it if not confirmed" do
command_line_config.stub(:gets => 'no')
command_line_config.run
expect(File.exist?('autotest/discover.rb')).to be_true
end
end
context "with lib/tasks/rspec.rake" do
before do
FileUtils.mkdir_p('lib/tasks')
FileUtils.touch 'lib/tasks/rspec.rake'
end
it "asks whether to delete the file" do
command_line_config.should_receive(:puts).with(/delete/)
command_line_config.run
end
it "removes it if confirmed" do
command_line_config.stub(:gets => 'yes')
command_line_config.run
expect(File.exist?('lib/tasks/rspec.rake')).to be_false
end
it "leaves it if not confirmed" do
command_line_config.stub(:gets => 'no')
command_line_config.run
expect(File.exist?('lib/tasks/rspec.rake')).to be_true
end
end
end
context "given an arg" do
it "warns if arg received (no longer necessary)" do
config = ProjectInitializer.new("another_arg")
config.stub(:puts)
config.stub(:gets => 'no')
config.run
end
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/filter_manager_spec.rb 0000644 0000041 0000041 00000023521 12261207027 023215 0 ustar www-data www-data require 'spec_helper'
module RSpec::Core
describe FilterManager do
def opposite(name)
name =~ /^in/ ? name.sub(/^(in)/,'ex') : name.sub(/^(ex)/,'in')
end
%w[include inclusions exclude exclusions].each_slice(2) do |name, type|
describe "##{name}" do
it "merges #{type}" do
filter_manager = FilterManager.new
filter_manager.exclusions.clear # defaults
filter_manager.send name, :foo => :bar
filter_manager.send name, :baz => :bam
expect(filter_manager.send(type)).to eq(:foo => :bar, :baz => :bam)
end
it "overrides previous #{type} with (via merge)" do
filter_manager = FilterManager.new
filter_manager.exclusions.clear # defaults
filter_manager.send name, :foo => 1
filter_manager.send name, :foo => 2
expect(filter_manager.send(type)).to eq(:foo => 2)
end
it "deletes matching opposites" do
filter_manager = FilterManager.new
filter_manager.exclusions.clear # defaults
filter_manager.send opposite(name), :foo => 1
filter_manager.send name, :foo => 2
expect(filter_manager.send(type)).to eq(:foo => 2)
expect(filter_manager.send(opposite(type))).to be_empty
end
if name == "include"
[:locations, :line_numbers, :full_description].each do |filter|
context "with :#{filter}" do
it "clears previous inclusions" do
filter_manager = FilterManager.new
filter_manager.include :foo => :bar
filter_manager.include filter => "value"
expect(filter_manager.inclusions).to eq({filter => "value"})
end
it "does nothing when :#{filter} previously set" do
filter_manager = FilterManager.new
filter_manager.include filter => "a_value"
filter_manager.include :foo => :bar
expect(filter_manager.inclusions).to eq(filter => "a_value")
end
end
end
end
end
describe "##{name}!" do
it "replaces existing #{type}" do
filter_manager = FilterManager.new
filter_manager.exclusions.clear # defaults
filter_manager.send name, :foo => 1, :bar => 2
filter_manager.send "#{name}!", :foo => 3
expect(filter_manager.send(type)).to eq(:foo => 3)
end
it "deletes matching opposites" do
filter_manager = FilterManager.new
filter_manager.exclusions.clear # defaults
filter_manager.send opposite(name), :foo => 1
filter_manager.send "#{name}!", :foo => 2
expect(filter_manager.send(type)).to eq(:foo => 2)
expect(filter_manager.send(opposite(type))).to be_empty
end
end
describe "##{name}_with_low_priority" do
it "ignores new #{type} if same key exists" do
filter_manager = FilterManager.new
filter_manager.exclusions.clear # defaults
filter_manager.send name, :foo => 1
filter_manager.send "#{name}_with_low_priority", :foo => 2
expect(filter_manager.send(type)).to eq(:foo => 1)
end
it "ignores new #{type} if same key exists in opposite" do
filter_manager = FilterManager.new
filter_manager.exclusions.clear # defaults
filter_manager.send opposite(name), :foo => 1
filter_manager.send "#{name}_with_low_priority", :foo => 1
expect(filter_manager.send(type)).to be_empty
expect(filter_manager.send(opposite(type))).to eq(:foo => 1)
end
it "keeps new #{type} if same key exists in opposite but values are different" do
filter_manager = FilterManager.new
filter_manager.exclusions.clear # defaults
filter_manager.send opposite(name), :foo => 1
filter_manager.send "#{name}_with_low_priority", :foo => 2
expect(filter_manager.send(type)).to eq(:foo => 2)
expect(filter_manager.send(opposite(type))).to eq(:foo => 1)
end
end
end
describe "#prune" do
def filterable_object_with(args = {})
object = double('a filterable object')
object.stub(:any_apply?) { |f| Metadata.new(args).any_apply?(f) }
object
end
it "includes objects with tags matching inclusions" do
included = filterable_object_with({:foo => :bar})
excluded = filterable_object_with
filter_manager = FilterManager.new
filter_manager.include :foo => :bar
expect(filter_manager.prune([included, excluded])).to eq([included])
end
it "excludes objects with tags matching exclusions" do
included = filterable_object_with
excluded = filterable_object_with({:foo => :bar})
filter_manager = FilterManager.new
filter_manager.exclude :foo => :bar
expect(filter_manager.prune([included, excluded])).to eq([included])
end
it "prefers exclusion when matches previously set inclusion" do
included = filterable_object_with
excluded = filterable_object_with({:foo => :bar})
filter_manager = FilterManager.new
filter_manager.include :foo => :bar
filter_manager.exclude :foo => :bar
expect(filter_manager.prune([included, excluded])).to eq([included])
end
it "prefers inclusion when matches previously set exclusion" do
included = filterable_object_with({:foo => :bar})
excluded = filterable_object_with
filter_manager = FilterManager.new
filter_manager.exclude :foo => :bar
filter_manager.include :foo => :bar
expect(filter_manager.prune([included, excluded])).to eq([included])
end
it "prefers previously set inclusion when exclusion matches but has lower priority" do
included = filterable_object_with({:foo => :bar})
excluded = filterable_object_with
filter_manager = FilterManager.new
filter_manager.include :foo => :bar
filter_manager.exclude_with_low_priority :foo => :bar
expect(filter_manager.prune([included, excluded])).to eq([included])
end
it "prefers previously set exclusion when inclusion matches but has lower priority" do
included = filterable_object_with
excluded = filterable_object_with({:foo => :bar})
filter_manager = FilterManager.new
filter_manager.exclude :foo => :bar
filter_manager.include_with_low_priority :foo => :bar
expect(filter_manager.prune([included, excluded])).to eq([included])
end
end
describe "#inclusions#description" do
it 'cleans up the description' do
project_dir = File.expand_path('.')
expect(lambda { }.inspect).to include(project_dir)
expect(lambda { }.inspect).to include(' (lambda)') if RUBY_VERSION > '1.9'
expect(lambda { }.inspect).to include('0x')
filter_manager = FilterManager.new
filter_manager.include :foo => lambda { }
expect(filter_manager.inclusions.description).not_to include(project_dir)
expect(filter_manager.inclusions.description).not_to include(' (lambda)')
expect(filter_manager.inclusions.description).not_to include('0x')
end
end
describe "#exclusions#description" do
it 'cleans up the description' do
project_dir = File.expand_path('.')
expect(lambda { }.inspect).to include(project_dir)
expect(lambda { }.inspect).to include(' (lambda)') if RUBY_VERSION > '1.9'
expect(lambda { }.inspect).to include('0x')
filter_manager = FilterManager.new
filter_manager.exclude :foo => lambda { }
expect(filter_manager.exclusions.description).not_to include(project_dir)
expect(filter_manager.exclusions.description).not_to include(' (lambda)')
expect(filter_manager.exclusions.description).not_to include('0x')
end
it 'returns `{}` when it only contains the default filters' do
filter_manager = FilterManager.new
expect(filter_manager.exclusions.description).to eq({}.inspect)
end
it 'includes other filters' do
filter_manager = FilterManager.new
filter_manager.exclude :foo => :bar
expect(filter_manager.exclusions.description).to eq({ :foo => :bar }.inspect)
end
it 'deprecates an overridden :if filter' do
expect(RSpec).to receive(:deprecate).with(/exclude\(:if/)
filter_manager = FilterManager.new
filter_manager.exclude :if => :custom_filter
end
it 'deprecates an :if filter overridden with low priority' do
expect(RSpec).to receive(:deprecate).with(/exclude\(:if/)
filter_manager = FilterManager.new
filter_manager.exclude_with_low_priority :if => :custom_filter
end
it 'deprecates an overridden :unless filter' do
expect(RSpec).to receive(:deprecate).with(/exclude\(:unless/)
filter_manager = FilterManager.new
filter_manager.exclude :unless => :custom_filter
end
it 'deprecates an :unless filter overridden with low priority' do
expect(RSpec).to receive(:deprecate).with(/exclude\(:unless/)
filter_manager = FilterManager.new
filter_manager.exclude_with_low_priority :unless => :custom_filter
end
it 'includes an overriden :if filter' do
allow(RSpec).to receive(:deprecate)
filter_manager = FilterManager.new
filter_manager.exclude :if => :custom_filter
expect(filter_manager.exclusions.description).to eq({ :if => :custom_filter }.inspect)
end
it 'includes an overriden :unless filter' do
allow(RSpec).to receive(:deprecate)
filter_manager = FilterManager.new
filter_manager.exclude :unless => :custom_filter
expect(filter_manager.exclusions.description).to eq({ :unless => :custom_filter }.inspect)
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/deprecation_spec.rb 0000644 0000041 0000041 00000003445 12261207027 022536 0 ustar www-data www-data require "spec_helper"
describe RSpec::Core::Deprecation do
describe "#deprecate" do
context "old API with individual args" do
it "includes the method to deprecate" do
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method")
RSpec.deprecate("deprecated_method")
end
it "includes the replacement when provided" do
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method", :replacement => "replacement")
RSpec.deprecate("deprecated_method", "replacement")
end
it "adds the call site" do
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
RSpec.deprecate("deprecated_method")
end
it "doesn't override the existing callsite" do
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :call_site => "/path")
RSpec.deprecate("deprecated_method", :call_site => "/path")
end
end
context "new API with a hash after the first arg" do
it "passes the hash to the reporter" do
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method", :replacement => "replacement")
RSpec.deprecate("deprecated_method", :replacement => "replacement")
end
it "adds the call site" do
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
RSpec.deprecate("deprecated_method")
end
end
end
describe "#warn_deprecation" do
it "puts message in a hash" do
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :message => "this is the message")
RSpec.warn_deprecation("this is the message")
end
end
end
rspec-core-2.14.7/spec/rspec/core/shared_context_spec.rb 0000644 0000041 0000041 00000005505 12261207027 023252 0 ustar www-data www-data require "spec_helper"
describe RSpec::SharedContext do
it "is accessible as RSpec::Core::SharedContext" do
RSpec::Core::SharedContext
end
it "is accessible as RSpec::SharedContext" do
RSpec::SharedContext
end
it "supports before and after hooks" do
before_all_hook = false
before_each_hook = false
after_each_hook = false
after_all_hook = false
shared = Module.new do
extend RSpec::SharedContext
before(:all) { before_all_hook = true }
before(:each) { before_each_hook = true }
after(:each) { after_each_hook = true }
after(:all) { after_all_hook = true }
end
group = RSpec::Core::ExampleGroup.describe do
include shared
example { }
end
group.run
expect(before_all_hook).to be_true
expect(before_each_hook).to be_true
expect(after_each_hook).to be_true
expect(after_all_hook).to be_true
end
it "runs the before each hooks in configuration before those of the shared context" do
ordered_hooks = []
RSpec.configure do |c|
c.before(:each) { ordered_hooks << "config" }
end
shared_context("before each stuff", :example => :before_each_hook_order) do
before(:each) { ordered_hooks << "shared_context"}
end
group = RSpec::Core::ExampleGroup.describe :example => :before_each_hook_order do
before(:each) { ordered_hooks << "example_group" }
example {}
end
group.run
expect(ordered_hooks).to be == ["config", "shared_context", "example_group"]
end
it "supports let" do
shared = Module.new do
extend RSpec::SharedContext
let(:foo) { 'foo' }
end
group = RSpec::Core::ExampleGroup.describe do
include shared
end
expect(group.new.foo).to eq('foo')
end
it 'supports explicit subjects' do
shared = Module.new do
extend RSpec::SharedContext
subject { 17 }
end
group = RSpec::Core::ExampleGroup.describe do
include shared
end
expect(group.new.subject).to eq(17)
end
it 'supports `its` with an implicit subject' do
shared = Module.new do
extend RSpec::SharedContext
its(:size) { should eq 0 }
end
group = RSpec::Core::ExampleGroup.describe(Array) do
include shared
end
group.run
expect(group.children.first.examples.first.execution_result).to include(:status => "passed")
end
%w[describe context].each do |method_name|
it "supports nested example groups using #{method_name}" do
shared = Module.new do
extend RSpec::SharedContext
send(method_name, "nested using describe") do
example {}
end
end
group = RSpec::Core::ExampleGroup.describe do
include shared
end
group.run
expect(group.children.length).to eq(1)
expect(group.children.first.examples.length).to eq(1)
end
end
end
rspec-core-2.14.7/spec/rspec/core/example_spec.rb 0000644 0000041 0000041 00000036467 12261207027 021706 0 ustar www-data www-data require 'spec_helper'
require 'pp'
require 'stringio'
describe RSpec::Core::Example, :parent_metadata => 'sample' do
let(:example_group) do
RSpec::Core::ExampleGroup.describe('group description')
end
let(:example_instance) do
example_group.example('example description') { }
end
it_behaves_like "metadata hash builder" do
def metadata_hash(*args)
example = example_group.example('example description', *args)
example.metadata
end
end
def capture_stdout
orig_stdout = $stdout
$stdout = StringIO.new
yield
$stdout.string
ensure
$stdout = orig_stdout
end
it 'can be pretty printed' do
output = ignoring_warnings { capture_stdout { pp example_instance } }
expect(output).to include("RSpec::Core::Example")
end
describe "#exception" do
it "supplies the first exception raised, if any" do
example = example_group.example { raise "first" }
example_group.after { raise "second" }
example_group.run
expect(example.exception.message).to eq("first")
end
it "returns nil if there is no exception" do
example = example_group.example('example') { }
example_group.run
expect(example.exception).to be_nil
end
end
describe "when there is an explicit description" do
context "when RSpec.configuration.format_docstrings is set to a block" do
it "formats the description using the block" do
RSpec.configuration.format_docstrings { |s| s.strip }
example = example_group.example(' an example with whitespace ') {}
example_group.run
expect(example.description).to eql('an example with whitespace')
end
end
end
describe "when there is no explicit description" do
def expect_with(*frameworks)
RSpec.configuration.stub(:expecting_with_rspec?).and_return(frameworks.include?(:rspec))
if frameworks.include?(:stdlib)
example_group.class_eval do
def assert(val)
raise "Expected #{val} to be true" unless val
end
end
end
end
context "when RSpec.configuration.format_docstrings is set to a block" do
it "formats the description using the block" do
RSpec.configuration.format_docstrings { |s| s.upcase }
example_group.example { expect(5).to eq(5) }
example_group.run
pattern = /EXAMPLE AT #{relative_path(__FILE__).upcase}:#{__LINE__ - 2}/
expect(example_group.examples.first.description).to match(pattern)
end
end
context "when `expect_with :rspec` is configured" do
before(:each) { expect_with :rspec }
it "uses the matcher-generated description" do
example_group.example { expect(5).to eq(5) }
example_group.run
expect(example_group.examples.first.description).to eq("should eq 5")
end
it "uses the matcher-generated description in the full description" do
example_group.example { expect(5).to eq(5) }
example_group.run
expect(example_group.examples.first.full_description).to eq("group description should eq 5")
end
it "uses the file and line number if there is no matcher-generated description" do
example = example_group.example {}
example_group.run
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
end
it "uses the file and line number if there is an error before the matcher" do
example = example_group.example { expect(5).to eq(5) }
example_group.before { raise }
example_group.run
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 3}/)
end
end
context "when `expect_with :rspec, :stdlib` is configured" do
before(:each) { expect_with :rspec, :stdlib }
it "uses the matcher-generated description" do
example_group.example { expect(5).to eq(5) }
example_group.run
expect(example_group.examples.first.description).to eq("should eq 5")
end
it "uses the file and line number if there is no matcher-generated description" do
example = example_group.example {}
example_group.run
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
end
it "uses the file and line number if there is an error before the matcher" do
example = example_group.example { expect(5).to eq(5) }
example_group.before { raise }
example_group.run
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 3}/)
end
end
context "when `expect_with :stdlib` is configured" do
before(:each) { expect_with :stdlib }
it "does not attempt to get the generated description from RSpec::Matchers" do
RSpec::Matchers.should_not_receive(:generated_description)
example_group.example { assert 5 == 5 }
example_group.run
end
it "uses the file and line number" do
example = example_group.example { assert 5 == 5 }
example_group.run
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
end
end
end
describe '#described_class' do
it "returns the class (if any) of the outermost example group" do
expect(described_class).to eq(RSpec::Core::Example)
end
end
describe "accessing metadata within a running example" do
it "has a reference to itself when running" do
expect(example.description).to eq("has a reference to itself when running")
end
it "can access the example group's top level metadata as if it were its own" do
expect(example.example_group.metadata).to include(:parent_metadata => 'sample')
expect(example.metadata).to include(:parent_metadata => 'sample')
end
end
describe "accessing options within a running example" do
it "can look up option values by key", :demo => :data do
expect(example.metadata[:demo]).to eq(:data)
end
end
describe "#run" do
it "sets its reference to the example group instance to nil" do
group = RSpec::Core::ExampleGroup.describe do
example('example') { expect(1).to eq(1) }
end
group.run
expect(group.examples.first.instance_variable_get("@example_group_instance")).to be_nil
end
it "runs after(:each) when the example passes" do
after_run = false
group = RSpec::Core::ExampleGroup.describe do
after(:each) { after_run = true }
example('example') { expect(1).to eq(1) }
end
group.run
expect(after_run).to be_true, "expected after(:each) to be run"
end
it "runs after(:each) when the example fails" do
after_run = false
group = RSpec::Core::ExampleGroup.describe do
after(:each) { after_run = true }
example('example') { expect(1).to eq(2) }
end
group.run
expect(after_run).to be_true, "expected after(:each) to be run"
end
it "runs after(:each) when the example raises an Exception" do
after_run = false
group = RSpec::Core::ExampleGroup.describe do
after(:each) { after_run = true }
example('example') { raise "this error" }
end
group.run
expect(after_run).to be_true, "expected after(:each) to be run"
end
context "with an after(:each) that raises" do
it "runs subsequent after(:each)'s" do
after_run = false
group = RSpec::Core::ExampleGroup.describe do
after(:each) { after_run = true }
after(:each) { raise "FOO" }
example('example') { expect(1).to eq(1) }
end
group.run
expect(after_run).to be_true, "expected after(:each) to be run"
end
it "stores the exception" do
group = RSpec::Core::ExampleGroup.describe
group.after(:each) { raise "FOO" }
example = group.example('example') { expect(1).to eq(1) }
group.run
expect(example.metadata[:execution_result][:exception].message).to eq("FOO")
end
end
it "wraps before/after(:each) inside around" do
results = []
group = RSpec::Core::ExampleGroup.describe do
around(:each) do |e|
results << "around (before)"
e.run
results << "around (after)"
end
before(:each) { results << "before" }
after(:each) { results << "after" }
example { results << "example" }
end
group.run
expect(results).to eq([
"around (before)",
"before",
"example",
"after",
"around (after)"
])
end
context "clearing ivars" do
it "sets ivars to nil to prep them for GC" do
group = RSpec::Core::ExampleGroup.describe do
before(:all) { @before_all = :before_all }
before(:each) { @before_each = :before_each }
after(:each) { @after_each = :after_each }
after(:all) { @after_all = :after_all }
end
group.example("does something") do
expect(@before_all).to eq(:before_all)
expect(@before_each).to eq(:before_each)
end
expect(group.run(double.as_null_object)).to be_true
group.new do |example|
%w[@before_all @before_each @after_each @after_all].each do |ivar|
expect(example.instance_variable_get(ivar)).to be_nil
end
end
end
it "does not impact the before_all_ivars which are copied to each example" do
group = RSpec::Core::ExampleGroup.describe do
before(:all) { @before_all = "abc" }
example("first") { expect(@before_all).not_to be_nil }
example("second") { expect(@before_all).not_to be_nil }
end
expect(group.run).to be_true
end
end
context 'when the example raises an error' do
def run_and_capture_reported_message(group)
reported_msg = nil
# We can't use should_receive(:message).with(/.../) here,
# because if that fails, it would fail within our example-under-test,
# and since there's already two errors, it would just be reported again.
RSpec.configuration.reporter.stub(:message) { |msg| reported_msg = msg }
group.run
reported_msg
end
it "prints any around hook errors rather than silencing them" do
group = RSpec::Core::ExampleGroup.describe do
around(:each) { |e| e.run; raise "around" }
example("e") { raise "example" }
end
message = run_and_capture_reported_message(group)
expect(message).to match(/An error occurred in an around.* hook/i)
end
it "prints any after hook errors rather than silencing them" do
group = RSpec::Core::ExampleGroup.describe do
after(:each) { raise "after" }
example("e") { raise "example" }
end
message = run_and_capture_reported_message(group)
expect(message).to match(/An error occurred in an after.* hook/i)
end
it 'does not print mock expectation errors' do
group = RSpec::Core::ExampleGroup.describe do
example do
foo = double
foo.should_receive(:bar)
raise "boom"
end
end
message = run_and_capture_reported_message(group)
expect(message).to be_nil
end
it "leaves a raised exception unmodified (GH-1103)" do
# set the backtrace, otherwise MRI will build a whole new object,
# and thus mess with our expectations. Rubinius and JRuby are not
# affected.
exception = StandardError.new
exception.set_backtrace([])
group = RSpec::Core::ExampleGroup.describe do
example { raise exception.freeze }
end
group.run
actual = group.examples.first.metadata[:execution_result][:exception]
expect(actual.__id__).to eq(exception.__id__)
end
end
end
describe "#pending" do
context "in the example" do
it "sets the example to pending" do
group = RSpec::Core::ExampleGroup.describe do
example { pending }
end
group.run
expect(group.examples.first).to be_pending
end
it "allows post-example processing in around hooks (see https://github.com/rspec/rspec-core/issues/322)" do
blah = nil
group = RSpec::Core::ExampleGroup.describe do
around do |example|
example.run
blah = :success
end
example { pending }
end
group.run
expect(blah).to be(:success)
end
context "with a block" do
it "sets the example to pending if block fails" do
group = RSpec::Core::ExampleGroup.describe do
example do
pending { expect(1).to eq(2) }
end
end
group.run
expect(group.examples.first.metadata[:execution_result][:status]).to eq('pending')
expect(group.examples.first.metadata[:execution_result][:pending_fixed]).to eq(false)
end
it "fails if block is fixed, i.e. does not raise" do
group = RSpec::Core::ExampleGroup.describe do
example do
pending {}
end
end
group.run
expect(group.examples.first.metadata[:execution_result][:status]).to eq('failed')
expect(group.examples.first.metadata[:execution_result][:pending_fixed]).to eq(true)
end
end
end
context "in before(:each)" do
it "sets each example to pending" do
group = RSpec::Core::ExampleGroup.describe do
before(:each) { pending }
example {}
example {}
end
group.run
expect(group.examples.first).to be_pending
expect(group.examples.last).to be_pending
end
end
context "in before(:all)" do
it "sets each example to pending" do
group = RSpec::Core::ExampleGroup.describe do
before(:all) { pending }
example {}
example {}
end
group.run
expect(group.examples.first).to be_pending
expect(group.examples.last).to be_pending
end
end
context "in around(:each)" do
it "sets the example to pending" do
group = RSpec::Core::ExampleGroup.describe do
around(:each) { pending }
example {}
end
group.run
expect(group.examples.first).to be_pending
end
end
end
describe "timing" do
it "uses RSpec::Core::Time as to not be affected by changes to time in examples" do
reporter = double(:reporter).as_null_object
group = RSpec::Core::ExampleGroup.describe
example = group.example
example.__send__ :start, reporter
Time.stub(:now => Time.utc(2012, 10, 1))
example.__send__ :finish, reporter
expect(example.metadata[:execution_result][:run_time]).to be < 0.2
end
end
it 'does not interfere with per-example randomness when running examples in a random order' do
values = []
RSpec.configuration.order = :random
RSpec::Core::ExampleGroup.describe do
# The bug was only triggered when the examples
# were in nested contexts; see https://github.com/rspec/rspec-core/pull/837
context { example { values << rand } }
context { example { values << rand } }
end.run
expect(values.uniq).to have(2).values
end
end
rspec-core-2.14.7/spec/rspec/core/shared_example_group_spec.rb 0000644 0000041 0000041 00000010727 12261207027 024437 0 ustar www-data www-data require 'spec_helper'
module RandomTopLevelModule
def self.setup!
shared_examples_for("top level in module") {}
end
end
module RSpec::Core
describe SharedExampleGroup do
ExampleModule = Module.new
ExampleClass = Class.new
it 'does not add a bunch of private methods to Module' do
seg_methods = RSpec::Core::SharedExampleGroup.private_instance_methods
expect(Module.private_methods & seg_methods).to eq([])
end
module SharedExampleGroup
describe Registry do
it "can safely be reset when there aren't any shared groups" do
expect { Registry.new.clear }.to_not raise_error
end
end
end
before(:all) do
# this is a work around as SharedExampleGroup is not world safe
RandomTopLevelModule.setup!
end
%w[share_examples_for shared_examples_for shared_examples shared_context].each do |shared_method_name|
describe shared_method_name do
it "is exposed to the global namespace" do
expect(Kernel).to respond_to(shared_method_name)
end
it "displays a warning when adding a second shared example group with the same name" do
group = ExampleGroup.describe('example group')
group.send(shared_method_name, 'some shared group') {}
original_declaration = [__FILE__, __LINE__ - 1].join(':')
warning = nil
Kernel.stub(:warn) { |msg| warning = msg }
group.send(shared_method_name, 'some shared group') {}
second_declaration = [__FILE__, __LINE__ - 1].join(':')
expect(warning).to include('some shared group', original_declaration, second_declaration)
end
it 'works with top level defined examples in modules' do
expect(RSpec::configuration.reporter).to_not receive(:deprecation)
group = ExampleGroup.describe('example group') { include_context 'top level in module' }
end
["name", :name, ExampleModule, ExampleClass].each do |object|
type = object.class.name.downcase
context "given a #{type}" do
it "captures the given #{type} and block in the collection of shared example groups" do
implementation = lambda {}
send(shared_method_name, object, &implementation)
expect(SharedExampleGroup.registry.shared_example_groups[self][object]).to eq implementation
end
end
end
context "given a hash" do
it "delegates extend on configuration" do
implementation = Proc.new { def bar; 'bar'; end }
send(shared_method_name, :foo => :bar, &implementation)
a = RSpec.configuration.include_or_extend_modules.first
expect(a[0]).to eq(:extend)
expect(Class.new.extend(a[1]).new.bar).to eq('bar')
expect(a[2]).to eq(:foo => :bar)
end
end
context "given a string and a hash" do
it "captures the given string and block in the World's collection of shared example groups" do
implementation = lambda {}
send(shared_method_name, "name", :foo => :bar, &implementation)
expect(SharedExampleGroup.registry.shared_example_groups[self]["name"]).to eq implementation
end
it "delegates extend on configuration" do
implementation = Proc.new { def bar; 'bar'; end }
send(shared_method_name, "name", :foo => :bar, &implementation)
a = RSpec.configuration.include_or_extend_modules.first
expect(a[0]).to eq(:extend)
expect(Class.new.extend(a[1]).new.bar).to eq('bar')
expect(a[2]).to eq(:foo => :bar)
end
end
end
end
describe "#share_as" do
before { allow(RSpec).to receive(:deprecate) }
it "is exposed to the global namespace" do
expect(Kernel).to respond_to("share_as")
end
it "adds examples to current example_group using include", :compat => 'rspec-1.2' do
share_as('Cornucopia') do
it "is plentiful" do
expect(5).to eq(4)
end
end
group = ExampleGroup.describe('group') { include Cornucopia }
phantom_group = group.children.first
expect(phantom_group.description).to eql("")
expect(phantom_group.metadata[:shared_group_name]).to eql('Cornucopia')
expect(phantom_group.examples.length).to eq(1)
expect(phantom_group.examples.first.metadata[:description]).to eq("is plentiful")
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/resources/ 0000755 0000041 0000041 00000000000 12261207027 020706 5 ustar www-data www-data rspec-core-2.14.7/spec/rspec/core/resources/custom_example_group_runner.rb 0000644 0000041 0000041 00000000327 12261207027 027067 0 ustar www-data www-data module Custom
class ExampleGroupRunner
attr_reader :options, :arg
def initialize(options, arg)
@options, @arg = options, arg
end
def load_files(files)
end
def run
end
end
end
rspec-core-2.14.7/spec/rspec/core/resources/a_bar.rb 0000644 0000041 0000041 00000000000 12261207027 022265 0 ustar www-data www-data rspec-core-2.14.7/spec/rspec/core/resources/formatter_specs.rb 0000644 0000041 0000041 00000002256 12261207027 024440 0 ustar www-data www-data # Deliberately named _specs.rb to avoid being loaded except when specified
describe "pending spec with no implementation" do
it "is pending"
end
describe "pending command with block format" do
context "with content that would fail" do
it "is pending" do
pending do
expect(1).to eq(2)
end
end
end
context "with content that would pass" do
it "fails" do
pending do
expect(1).to eq(1)
end
end
end
end
describe "passing spec" do
it "passes" do
expect(1).to eq(1)
end
end
describe "failing spec" do
it "fails" do
expect(1).to eq(2)
end
end
describe "a failing spec with odd backtraces" do
it "fails with a backtrace that has no file" do
require 'erb'
ERB.new("<%= raise 'foo' %>").result
end
it "fails with a backtrace containing an erb file" do
e = Exception.new
def e.backtrace
["/foo.html.erb:1:in `': foo (RuntimeError)",
" from /lib/ruby/1.9.1/erb.rb:753:in `eval'"]
end
def e.message
# Redefining message steps around this behaviour
# on JRuby: http://jira.codehaus.org/browse/JRUBY-5637
self.class.name
end
raise e
end
end
rspec-core-2.14.7/spec/rspec/core/resources/utf8_encoded.rb 0000644 0000041 0000041 00000000174 12261207027 023604 0 ustar www-data www-data # encoding: utf-8
module Custom
class ExampleUTF8ClassNameVarietà
def self.è
così = :però
end
end
end
rspec-core-2.14.7/spec/rspec/core/resources/a_spec.rb 0000644 0000041 0000041 00000000045 12261207027 022464 0 ustar www-data www-data # Empty - used by ../options_spec.rb
rspec-core-2.14.7/spec/rspec/core/resources/a_foo.rb 0000644 0000041 0000041 00000000000 12261207027 022304 0 ustar www-data www-data rspec-core-2.14.7/spec/rspec/core/configuration_options_spec.rb 0000644 0000041 0000041 00000037051 12261207027 024663 0 ustar www-data www-data require 'spec_helper'
require 'ostruct'
require 'rspec/core/drb_options'
describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolated_home => true do
include ConfigOptionsHelper
it "warns when HOME env var is not set", :unless => (RUBY_PLATFORM == 'java') do
without_env_vars 'HOME' do
coo = RSpec::Core::ConfigurationOptions.new([])
coo.should_receive(:warn)
coo.parse_options
end
end
it "duplicates the arguments array" do
args = ['-e', 'some spec']
coo = RSpec::Core::ConfigurationOptions.new(args)
coo.parse_options
expect(args).to eq(['-e', 'some spec'])
end
describe "#configure" do
it "sends libs before requires" do
opts = config_options_object(*%w[--require a/path -I a/lib])
config = double("config").as_null_object
config.should_receive(:libs=).ordered
config.should_receive(:setup_load_path_and_require).ordered
opts.configure(config)
end
it "sends loads requires before loading specs" do
opts = config_options_object(*%w[-rspec_helper])
config = double("config").as_null_object
expect(config).to receive(:setup_load_path_and_require).ordered
expect(config).to receive(:files_or_directories_to_run=).ordered
opts.configure(config)
end
it "sets up load path and requires before formatter" do
opts = config_options_object(*%w[--require a/path -f a/formatter])
config = double("config").as_null_object
config.should_receive(:setup_load_path_and_require).ordered
config.should_receive(:add_formatter).ordered
opts.configure(config)
end
it "sends default_path before files_or_directories_to_run" do
opts = config_options_object(*%w[--default_path spec])
config = double("config").as_null_object
config.should_receive(:force).with(:default_path => 'spec').ordered
config.should_receive(:files_or_directories_to_run=).ordered
opts.configure(config)
end
it "sends pattern before files_or_directories_to_run" do
opts = config_options_object(*%w[--pattern **/*.spec])
config = double("config").as_null_object
config.should_receive(:force).with(:pattern => '**/*.spec').ordered
config.should_receive(:files_or_directories_to_run=).ordered
opts.configure(config)
end
it "assigns inclusion_filter" do
opts = config_options_object(*%w[--tag awesome])
config = RSpec::Core::Configuration.new
opts.configure(config)
expect(config.inclusion_filter).to have_key(:awesome)
end
it "merges the :exclusion_filter option with the default exclusion_filter" do
opts = config_options_object(*%w[--tag ~slow])
config = RSpec::Core::Configuration.new
opts.configure(config)
expect(config.exclusion_filter).to have_key(:slow)
end
it "forces color_enabled" do
opts = config_options_object(*%w[--color])
config = RSpec::Core::Configuration.new
config.should_receive(:force).with(:color => true)
opts.configure(config)
end
[
["--failure-exit-code", "3", :failure_exit_code, 3 ],
["--pattern", "foo/bar", :pattern, "foo/bar"],
["--failure-exit-code", "37", :failure_exit_code, 37],
["--default_path", "behavior", :default_path, "behavior"],
["--order", "rand", :order, "rand"],
["--seed", "37", :order, "rand:37"],
["--drb-port", "37", :drb_port, 37]
].each do |cli_option, cli_value, config_key, config_value|
it "forces #{config_key}" do
opts = config_options_object(*[cli_option, cli_value].compact)
config = RSpec::Core::Configuration.new
config.should_receive(:force) do |pair|
expect(pair.keys.first).to eq(config_key)
expect(pair.values.first).to eq(config_value)
end
opts.configure(config)
end
end
it "sets debug directly" do
opts = config_options_object("--debug")
config = RSpec::Core::Configuration.new
config.should_receive(:debug=).with(true)
opts.configure(config)
end
it "merges --require specified by multiple configuration sources" do
with_env_vars 'SPEC_OPTS' => "--require file_from_env" do
opts = config_options_object(*%w[--require file_from_opts])
config = RSpec::Core::Configuration.new
config.should_receive(:require).with("file_from_opts")
config.should_receive(:require).with("file_from_env")
opts.configure(config)
end
end
it "merges --I specified by multiple configuration sources" do
with_env_vars 'SPEC_OPTS' => "-I dir_from_env" do
opts = config_options_object(*%w[-I dir_from_opts])
config = RSpec::Core::Configuration.new
config.should_receive(:libs=).with(["dir_from_opts", "dir_from_env"])
opts.configure(config)
end
end
end
describe "-c, --color, and --colour" do
it "sets :color => true" do
expect(parse_options('-c')).to include(:color => true)
expect(parse_options('--color')).to include(:color => true)
expect(parse_options('--colour')).to include(:color => true)
end
end
describe "--no-color" do
it "sets :color => false" do
expect(parse_options('--no-color')).to include(:color => false)
end
it "overrides previous :color => true" do
expect(parse_options('--color', '--no-color')).to include(:color => false)
end
it "gets overriden by a subsequent :color => true" do
expect(parse_options('--no-color', '--color')).to include(:color => true)
end
end
describe "-I" do
example "adds to :libs" do
expect(parse_options('-I', 'a_dir')).to include(:libs => ['a_dir'])
end
example "can be used more than once" do
expect(parse_options('-I', 'dir_1', '-I', 'dir_2')).to include(:libs => ['dir_1','dir_2'])
end
end
describe '--require' do
example "requires files" do
expect(parse_options('--require', 'a/path')).to include(:requires => ['a/path'])
end
example "can be used more than once" do
expect(parse_options('--require', 'path/1', '--require', 'path/2')).to include(:requires => ['path/1','path/2'])
end
end
describe "--format, -f" do
it "sets :formatter" do
[['--format', 'd'], ['-f', 'd'], '-fd'].each do |args|
expect(parse_options(*args)).to include(:formatters => [['d']])
end
end
example "can accept a class name" do
expect(parse_options('-fSome::Formatter::Class')).to include(:formatters => [['Some::Formatter::Class']])
end
end
describe "--profile, -p" do
it "sets :profile_examples" do
expect(parse_options('-p')).to include(:profile_examples => true)
expect(parse_options('--profile')).to include(:profile_examples => true)
expect(parse_options('-p', '4')).to include(:profile_examples => 4)
expect(parse_options('--profile', '3')).to include(:profile_examples => 3)
end
end
describe "--no-profile" do
it "sets :profile_examples to false" do
expect(parse_options('--no-profile')).to include(:profile_examples => false)
end
end
describe '--line_number' do
it "sets :line_number" do
expect(parse_options('-l','3')).to include(:line_numbers => ['3'])
expect(parse_options('--line_number','3')).to include(:line_numbers => ['3'])
end
it "can be specified multiple times" do
expect(parse_options('-l','3', '-l', '6')).to include(:line_numbers => ['3', '6'])
expect(parse_options('--line_number','3', '--line_number', '6')).to include(:line_numbers => ['3', '6'])
end
end
describe "--example" do
it "sets :full_description" do
expect(parse_options('--example','foo')).to include(:full_description => [/foo/])
expect(parse_options('-e','bar')).to include(:full_description => [/bar/])
end
end
describe "--backtrace, -b" do
it "sets full_backtrace on config" do
expect(parse_options("--backtrace")).to include(:full_backtrace => true)
expect(parse_options("-b")).to include(:full_backtrace => true)
end
end
describe "--debug, -d" do
it "sets :debug => true" do
expect(parse_options("--debug")).to include(:debug => true)
expect(parse_options("-d")).to include(:debug => true)
end
end
describe "--fail-fast" do
it "defaults to false" do
expect(parse_options[:fail_fast]).to be_false
end
it "sets fail_fast on config" do
expect(parse_options("--fail-fast")[:fail_fast]).to be_true
end
end
describe "--failure-exit-code" do
it "sets :failure_exit_code" do
expect(parse_options('--failure-exit-code', '0')).to include(:failure_exit_code => 0)
expect(parse_options('--failure-exit-code', '1')).to include(:failure_exit_code => 1)
expect(parse_options('--failure-exit-code', '2')).to include(:failure_exit_code => 2)
end
it "overrides previous :failure_exit_code" do
expect(parse_options('--failure-exit-code', '2', '--failure-exit-code', '3')).to include(:failure_exit_code => 3)
end
end
describe "--options" do
it "sets :custom_options_file" do
expect(parse_options(*%w[-O my.opts])).to include(:custom_options_file => "my.opts")
expect(parse_options(*%w[--options my.opts])).to include(:custom_options_file => "my.opts")
end
end
describe "--drb, -X" do
context "combined with --debug" do
it "turns off the debugger if --drb is specified first" do
expect(config_options_object("--drb", "--debug").drb_argv).not_to include("--debug")
expect(config_options_object("--drb", "-d" ).drb_argv).not_to include("--debug")
expect(config_options_object("-X", "--debug").drb_argv).not_to include("--debug")
expect(config_options_object("-X", "-d" ).drb_argv).not_to include("--debug")
end
it "turns off the debugger option if --drb is specified later" do
expect(config_options_object("--debug", "--drb").drb_argv).not_to include("--debug")
expect(config_options_object("-d", "--drb").drb_argv).not_to include("--debug")
expect(config_options_object("--debug", "-X" ).drb_argv).not_to include("--debug")
expect(config_options_object("-d", "-X" ).drb_argv).not_to include("--debug")
end
it "turns off the debugger option if --drb is specified in the options file" do
File.open("./.rspec", "w") {|f| f << "--drb"}
expect(config_options_object("--debug").drb_argv).not_to include("--debug")
expect(config_options_object("-d" ).drb_argv).not_to include("--debug")
end
it "turns off the debugger option if --debug is specified in the options file" do
File.open("./.rspec", "w") {|f| f << "--debug"}
expect(config_options_object("--drb").drb_argv).not_to include("--debug")
expect(config_options_object("-X" ).drb_argv).not_to include("--debug")
end
end
it "does not send --drb back to the parser after parsing options" do
expect(config_options_object("--drb", "--color").drb_argv).not_to include("--drb")
end
end
describe "--no-drb" do
it "disables drb" do
expect(parse_options("--no-drb")).to include(:drb => false)
end
it "overrides a previous drb => true" do
expect(parse_options("--drb", "--no-drb")).to include(:drb => false)
end
it "gets overriden by a subsquent drb => true" do
expect(parse_options("--no-drb", "--drb")).to include(:drb => true)
end
end
describe "files_or_directories_to_run" do
it "parses files from '-c file.rb dir/file.rb'" do
expect(parse_options("-c", "file.rb", "dir/file.rb")).to include(
:files_or_directories_to_run => ["file.rb", "dir/file.rb"]
)
end
it "parses dir from 'dir'" do
expect(parse_options("dir")).to include(:files_or_directories_to_run => ["dir"])
end
it "parses dir and files from 'spec/file1_spec.rb, spec/file2_spec.rb'" do
expect(parse_options("dir", "spec/file1_spec.rb", "spec/file2_spec.rb")).to include(
:files_or_directories_to_run => ["dir", "spec/file1_spec.rb", "spec/file2_spec.rb"]
)
end
it "provides no files or directories if spec directory does not exist" do
FileTest.stub(:directory?).with("spec").and_return false
expect(parse_options()).to include(:files_or_directories_to_run => [])
end
end
describe "default_path" do
it "gets set before files_or_directories_to_run" do
config = double("config").as_null_object
config.should_receive(:force).with(:default_path => 'foo').ordered
config.should_receive(:files_or_directories_to_run=).ordered
opts = config_options_object("--default_path", "foo")
opts.configure(config)
end
end
describe "#filter_manager" do
it "returns the same object as RSpec::configuration.filter_manager" do
expect(config_options_object.filter_manager).to be(RSpec::configuration.filter_manager)
end
end
describe "sources: ~/.rspec, ./.rspec, ./.rspec-local, custom, CLI, and SPEC_OPTS" do
it "merges global, local, SPEC_OPTS, and CLI" do
File.open("./.rspec", "w") {|f| f << "--line 37"}
File.open("./.rspec-local", "w") {|f| f << "--format global"}
File.open(File.expand_path("~/.rspec"), "w") {|f| f << "--color"}
with_env_vars 'SPEC_OPTS' => "--debug --example 'foo bar'" do
options = parse_options("--drb")
expect(options[:color]).to be_true
expect(options[:line_numbers]).to eq(["37"])
expect(options[:debug]).to be_true
expect(options[:full_description]).to eq([/foo\ bar/])
expect(options[:drb]).to be_true
expect(options[:formatters]).to eq([['global']])
end
end
it "prefers SPEC_OPTS over CLI" do
with_env_vars 'SPEC_OPTS' => "--format spec_opts" do
expect(parse_options("--format", "cli")[:formatters]).to eq([['spec_opts']])
end
end
it "prefers CLI over file options" do
File.open("./.rspec", "w") {|f| f << "--format project"}
File.open(File.expand_path("~/.rspec"), "w") {|f| f << "--format global"}
expect(parse_options("--format", "cli")[:formatters]).to eq([['cli']])
end
it "prefers project file options over global file options" do
File.open("./.rspec", "w") {|f| f << "--format project"}
File.open(File.expand_path("~/.rspec"), "w") {|f| f << "--format global"}
expect(parse_options[:formatters]).to eq([['project']])
end
it "prefers local file options over project file options" do
File.open("./.rspec-local", "w") {|f| f << "--format local"}
File.open("./.rspec", "w") {|f| f << "--format global"}
expect(parse_options[:formatters]).to eq([['local']])
end
it "parses options file correctly if erb code has trimming options" do
File.open("./.rspec", "w") do |f|
f << "<% if true -%>\n"
f << "--format local\n"
f << "<%- end %>\n"
end
expect(parse_options[:formatters]).to eq([['local']])
end
context "with custom options file" do
it "ignores project and global options files" do
File.open("./.rspec", "w") {|f| f << "--format project"}
File.open(File.expand_path("~/.rspec"), "w") {|f| f << "--format global"}
File.open("./custom.opts", "w") {|f| f << "--color"}
options = parse_options("-O", "./custom.opts")
expect(options[:format]).to be_nil
expect(options[:color]).to be_true
end
it "parses -e 'full spec description'" do
File.open("./custom.opts", "w") {|f| f << "-e 'The quick brown fox jumps over the lazy dog'"}
options = parse_options("-O", "./custom.opts")
expect(options[:full_description]).to eq([/The\ quick\ brown\ fox\ jumps\ over\ the\ lazy\ dog/])
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/world_spec.rb 0000644 0000041 0000041 00000010664 12261207027 021371 0 ustar www-data www-data require 'spec_helper'
class Bar; end
class Foo; end
module RSpec::Core
describe RSpec::Core::World do
let(:configuration) { RSpec::Core::Configuration.new }
let(:world) { RSpec::Core::World.new(configuration) }
describe '#reset' do
it 'clears #example_groups' do
world.example_groups << :example_group
world.reset
expect(world.example_groups).to be_empty
end
end
describe "#example_groups" do
it "contains all registered example groups" do
group = RSpec::Core::ExampleGroup.describe("group"){}
world.register(group)
expect(world.example_groups).to include(group)
end
end
describe "#preceding_declaration_line (again)" do
let(:group) do
RSpec::Core::ExampleGroup.describe("group") do
example("example") {}
end
end
let(:second_group) do
RSpec::Core::ExampleGroup.describe("second_group") do
example("second_example") {}
end
end
let(:group_declaration_line) { group.metadata[:example_group][:line_number] }
let(:example_declaration_line) { group_declaration_line + 2 }
context "with one example" do
before { world.register(group) }
it "returns nil if no example or group precedes the line" do
expect(world.preceding_declaration_line(group_declaration_line - 1)).to be_nil
end
it "returns the argument line number if a group starts on that line" do
expect(world.preceding_declaration_line(group_declaration_line)).to eq(group_declaration_line)
end
it "returns the argument line number if an example starts on that line" do
expect(world.preceding_declaration_line(example_declaration_line)).to eq(example_declaration_line)
end
it "returns line number of a group that immediately precedes the argument line" do
expect(world.preceding_declaration_line(group_declaration_line + 1)).to eq(group_declaration_line)
end
it "returns line number of an example that immediately precedes the argument line" do
expect(world.preceding_declaration_line(example_declaration_line + 1)).to eq(example_declaration_line)
end
end
context "with two exaples and the second example is registre first" do
let(:second_group_declaration_line) { second_group.metadata[:example_group][:line_number] }
before do
world.register(second_group)
world.register(group)
end
it 'return line number of group if a group start on that line' do
expect(world.preceding_declaration_line(second_group_declaration_line)).to eq(second_group_declaration_line)
end
end
end
describe "#announce_filters" do
let(:reporter) { double('reporter').as_null_object }
before { world.stub(:reporter) { reporter } }
context "with no examples" do
before { world.stub(:example_count) { 0 } }
context "with no filters" do
it "announces" do
reporter.should_receive(:message).
with("No examples found.")
world.announce_filters
end
end
context "with an inclusion filter" do
it "announces" do
configuration.filter_run_including :foo => 'bar'
reporter.should_receive(:message).
with(/All examples were filtered out/)
world.announce_filters
end
end
context "with an inclusion filter and run_all_when_everything_filtered" do
it "announces" do
configuration.stub(:run_all_when_everything_filtered?) { true }
configuration.filter_run_including :foo => 'bar'
reporter.should_receive(:message).
with(/All examples were filtered out/)
world.announce_filters
end
end
context "with an exclusion filter" do
it "announces" do
configuration.filter_run_excluding :foo => 'bar'
reporter.should_receive(:message).
with(/All examples were filtered out/)
world.announce_filters
end
end
end
context "with examples" do
before { world.stub(:example_count) { 1 } }
context "with no filters" do
it "does not announce" do
reporter.should_not_receive(:message)
world.announce_filters
end
end
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/backtrace_cleaner_spec.rb 0000644 0000041 0000041 00000004677 12261207027 023661 0 ustar www-data www-data require "spec_helper"
module RSpec::Core
describe BacktraceCleaner do
context "with no patterns" do
it "keeps all lines" do
lines = ["/tmp/a_file", "some_random_text", "hello\330\271!"]
cleaner = BacktraceCleaner.new([], [])
expect(lines.all? {|line| cleaner.exclude? line}).to be_false
end
it 'is considered a full backtrace' do
expect(BacktraceCleaner.new([], []).full_backtrace?).to be_true
end
end
context "with an exclusion pattern but no inclusion patterns" do
it "excludes lines that match the exclusion pattern" do
cleaner = BacktraceCleaner.new([], [/remove/])
expect(cleaner.exclude? "remove me").to be_true
end
it "keeps lines that do not match the exclusion pattern" do
cleaner = BacktraceCleaner.new([], [/remove/])
expect(cleaner.exclude? "apple").to be_false
end
it 'is considered a partial backtrace' do
expect(BacktraceCleaner.new([], [/remove/]).full_backtrace?).to be_false
end
end
context "with an exclusion pattern and an inclusion pattern" do
it "excludes lines that match the exclusion pattern but not the inclusion pattern" do
cleaner = BacktraceCleaner.new([/keep/], [/discard/])
expect(cleaner.exclude? "discard").to be_true
end
it "keeps lines that match the inclusion pattern and the exclusion pattern" do
cleaner = BacktraceCleaner.new([/hi/], [/.*/])
expect(cleaner.exclude? "hi").to be_false
end
it "keeps lines that match neither pattern" do
cleaner = BacktraceCleaner.new([/hi/], [/delete/])
expect(cleaner.exclude? "fish").to be_false
end
it 'is considered a partial backtrace' do
expect(BacktraceCleaner.new([], [/remove/]).full_backtrace?).to be_false
end
end
context "with an exclusion pattern that matches the current working directory" do
it "defaults to having one inclusion pattern, the current working directory" do
cleaner = BacktraceCleaner.new(nil, [/.*/])
expect(Dir.getwd =~ cleaner.inclusion_patterns.first).to be_true
end
end
context "with an exclusion pattern that does not match the current working directory" do
it "defaults to having no exclusion patterns" do
cleaner = BacktraceCleaner.new(nil, [/i_wont_match_a_directory/])
expect(cleaner.inclusion_patterns.length).to be_zero
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/example_group_spec.rb 0000644 0000041 0000041 00000113614 12261207027 023110 0 ustar www-data www-data require 'spec_helper'
class SelfObserver
def self.cache
@cache ||= []
end
def initialize
self.class.cache << self
end
end
module RSpec::Core
describe ExampleGroup do
it_behaves_like "metadata hash builder" do
def metadata_hash(*args)
group = ExampleGroup.describe('example description', *args)
group.metadata
end
end
context "when RSpec.configuration.format_docstrings is set to a block" do
it "formats the description with that block" do
RSpec.configuration.format_docstrings { |s| s.upcase }
group = ExampleGroup.describe(' an example ')
expect(group.description).to eq(' AN EXAMPLE ')
end
end
context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to false' do
before(:each) do
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = false }
end
it 'processes string args as part of the description' do
group = ExampleGroup.describe("some", "separate", "strings")
expect(group.description).to eq("some separate strings")
end
it 'processes symbol args as part of the description' do
Kernel.stub(:warn) # to silence Symbols as args warning
group = ExampleGroup.describe(:some, :separate, :symbols)
expect(group.description).to eq("some separate symbols")
end
end
context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to true' do
let(:group) { ExampleGroup.describe(:symbol) }
before(:each) do
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = true }
end
it 'does not treat the first argument as a metadata key even if it is a symbol' do
expect(group.metadata).not_to include(:symbol)
end
it 'treats the first argument as part of the description when it is a symbol' do
expect(group.description).to eq("symbol")
end
end
describe "top level group" do
it "runs its children" do
examples_run = []
group = ExampleGroup.describe("parent") do
describe("child") do
it "does something" do
examples_run << example
end
end
end
group.run
expect(examples_run).to have(1).example
end
context "with a failure in the top level group" do
it "runs its children " do
examples_run = []
group = ExampleGroup.describe("parent") do
it "fails" do
examples_run << example
raise "fail"
end
describe("child") do
it "does something" do
examples_run << example
end
end
end
group.run
expect(examples_run).to have(2).examples
end
end
describe "descendants" do
it "returns self + all descendants" do
group = ExampleGroup.describe("parent") do
describe("child") do
describe("grandchild 1") {}
describe("grandchild 2") {}
end
end
expect(group.descendants.size).to eq(4)
end
end
end
describe "child" do
it "is known by parent" do
parent = ExampleGroup.describe
child = parent.describe
expect(parent.children).to eq([child])
end
it "is not registered in world" do
world = RSpec::Core::World.new
parent = ExampleGroup.describe
world.register(parent)
parent.describe
expect(world.example_groups).to eq([parent])
end
end
describe "filtering" do
let(:world) { World.new }
shared_examples "matching filters" do
context "inclusion" do
before do
filter_manager = FilterManager.new
filter_manager.include filter_metadata
world.stub(:filter_manager => filter_manager)
end
it "includes examples in groups matching filter" do
group = ExampleGroup.describe("does something", spec_metadata)
group.stub(:world) { world }
all_examples = [ group.example("first"), group.example("second") ]
expect(group.filtered_examples).to eq(all_examples)
end
it "includes examples directly matching filter" do
group = ExampleGroup.describe("does something")
group.stub(:world) { world }
filtered_examples = [
group.example("first", spec_metadata),
group.example("second", spec_metadata)
]
group.example("third (not-filtered)")
expect(group.filtered_examples).to eq(filtered_examples)
end
end
context "exclusion" do
before do
filter_manager = FilterManager.new
filter_manager.exclude filter_metadata
world.stub(:filter_manager => filter_manager)
end
it "excludes examples in groups matching filter" do
group = ExampleGroup.describe("does something", spec_metadata)
group.stub(:world) { world }
[ group.example("first"), group.example("second") ]
expect(group.filtered_examples).to be_empty
end
it "excludes examples directly matching filter" do
group = ExampleGroup.describe("does something")
group.stub(:world) { world }
[
group.example("first", spec_metadata),
group.example("second", spec_metadata)
]
unfiltered_example = group.example("third (not-filtered)")
expect(group.filtered_examples).to eq([unfiltered_example])
end
end
end
context "matching false" do
let(:spec_metadata) { { :awesome => false }}
context "against false" do
let(:filter_metadata) { { :awesome => false }}
include_examples "matching filters"
end
context "against 'false'" do
let(:filter_metadata) { { :awesome => 'false' }}
include_examples "matching filters"
end
context "against :false" do
let(:filter_metadata) { { :awesome => :false }}
include_examples "matching filters"
end
end
context "matching true" do
let(:spec_metadata) { { :awesome => true }}
context "against true" do
let(:filter_metadata) { { :awesome => true }}
include_examples "matching filters"
end
context "against 'true'" do
let(:filter_metadata) { { :awesome => 'true' }}
include_examples "matching filters"
end
context "against :true" do
let(:filter_metadata) { { :awesome => :true }}
include_examples "matching filters"
end
end
context "matching a string" do
let(:spec_metadata) { { :type => 'special' }}
context "against a string" do
let(:filter_metadata) { { :type => 'special' }}
include_examples "matching filters"
end
context "against a symbol" do
let(:filter_metadata) { { :type => :special }}
include_examples "matching filters"
end
end
context "matching a symbol" do
let(:spec_metadata) { { :type => :special }}
context "against a string" do
let(:filter_metadata) { { :type => 'special' }}
include_examples "matching filters"
end
context "against a symbol" do
let(:filter_metadata) { { :type => :special }}
include_examples "matching filters"
end
end
context "with no filters" do
it "returns all" do
group = ExampleGroup.describe
group.stub(:world) { world }
example = group.example("does something")
expect(group.filtered_examples).to eq([example])
end
end
context "with no examples or groups that match filters" do
it "returns none" do
filter_manager = FilterManager.new
filter_manager.include :awesome => false
world.stub(:filter_manager => filter_manager)
group = ExampleGroup.describe
group.stub(:world) { world }
group.example("does something")
expect(group.filtered_examples).to eq([])
end
end
end
describe '#described_class' do
context "with a constant as the first parameter" do
it "is that constant" do
expect(ExampleGroup.describe(Object) { }.described_class).to eq(Object)
end
end
context "with a string as the first parameter" do
it "is nil" do
expect(ExampleGroup.describe("i'm a computer") { }.described_class).to be_nil
end
end
context "with a constant in an outer group" do
context "and a string in an inner group" do
it "is the top level constant" do
group = ExampleGroup.describe(String) do
describe :symbol do
example "described_class is String" do
expect(described_class).to eq(String)
end
end
end
expect(group.run).to be_true
end
end
context "and metadata redefinition after `described_class` call" do
it "is the redefined level constant" do
group = ExampleGroup.describe(String) do
described_class
metadata[:example_group][:described_class] = Object
describe :symbol do
example "described_class is Object" do
expect(described_class).to eq(Object)
end
end
end
expect(group.run).to be_true
end
end
end
context "in a nested group" do
it "inherits the described class/module from the outer group" do
group = ExampleGroup.describe(String) do
describe Array do
example "describes is String" do
expect(described_class).to eq(String)
end
end
end
expect(group.run).to be_true, "expected examples in group to pass"
end
end
context "for `describe(SomeClass)` within a `describe 'some string' group" do
def define_and_run_group(define_outer_example = false)
outer_described_class = inner_described_class = nil
ExampleGroup.describe("some string") do
example { outer_described_class = described_class } if define_outer_example
describe Array do
example { inner_described_class = described_class }
end
end.run
return outer_described_class, inner_described_class
end
it "has a `nil` described_class in the outer group" do
outer_described_class, _ = define_and_run_group(:define_outer_example)
expect(outer_described_class).to be(nil)
end
it "has the inner described class as the described_class of the inner group" do
_, inner_described_class = define_and_run_group
expect(inner_described_class).to be(Array)
# This is weird, but in RSpec 2.12 (and before, presumably),
# the `described_class` value would be incorrect if there was an
# example in the outer group, and correct if there was not one.
_, inner_described_class = define_and_run_group(:define_outer_example)
expect(inner_described_class).to be(Array)
end
end
end
describe '#described_class' do
it "is the same as described_class" do
expect(self.class.described_class).to eq(self.class.described_class)
end
end
describe '#description' do
it "grabs the description from the metadata" do
group = ExampleGroup.describe(Object, "my desc") { }
expect(group.description).to eq(group.metadata[:example_group][:description])
end
end
describe '#metadata' do
it "adds the third parameter to the metadata" do
expect(ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata).to include({ "foo" => 'bar' })
end
it "adds the the file_path to metadata" do
expect(ExampleGroup.describe(Object) { }.metadata[:example_group][:file_path]).to eq(relative_path(__FILE__))
end
it "has a reader for file_path" do
expect(ExampleGroup.describe(Object) { }.file_path).to eq(relative_path(__FILE__))
end
it "adds the line_number to metadata" do
expect(ExampleGroup.describe(Object) { }.metadata[:example_group][:line_number]).to eq(__LINE__)
end
end
[:focus, :focused, :fit].each do |example_alias|
describe "##{example_alias}" do
let(:focused_example) { ExampleGroup.describe.send example_alias, "a focused example" }
it 'defines an example that can be filtered with :focused => true' do
expect(focused_example.metadata[:focused]).to be_true
end
it 'defines an example that can be filtered with :focus => true' do
expect(focused_example.metadata[:focus]).to be_true
end
end
end
describe "#before, after, and around hooks" do
it "runs the before alls in order" do
group = ExampleGroup.describe
order = []
group.before(:all) { order << 1 }
group.before(:all) { order << 2 }
group.before(:all) { order << 3 }
group.example("example") {}
group.run
expect(order).to eq([1,2,3])
end
it "does not set RSpec.wants_to_quit in case of an error in before all (without fail_fast?)" do
group = ExampleGroup.describe
group.before(:all) { raise "error in before all" }
group.example("example") {}
group.run
expect(RSpec.wants_to_quit).to be_false
end
it "runs the before eachs in order" do
group = ExampleGroup.describe
order = []
group.before(:each) { order << 1 }
group.before(:each) { order << 2 }
group.before(:each) { order << 3 }
group.example("example") {}
group.run
expect(order).to eq([1,2,3])
end
it "runs the after eachs in reverse order" do
group = ExampleGroup.describe
order = []
group.after(:each) { order << 1 }
group.after(:each) { order << 2 }
group.after(:each) { order << 3 }
group.example("example") {}
group.run
expect(order).to eq([3,2,1])
end
it "runs the after alls in reverse order" do
group = ExampleGroup.describe
order = []
group.after(:all) { order << 1 }
group.after(:all) { order << 2 }
group.after(:all) { order << 3 }
group.example("example") {}
group.run
expect(order).to eq([3,2,1])
end
it "only runs before/after(:all) hooks from example groups that have specs that run" do
hooks_run = []
RSpec.configure do |c|
c.filter_run :focus => true
end
unfiltered_group = ExampleGroup.describe "unfiltered" do
before(:all) { hooks_run << :unfiltered_before_all }
after(:all) { hooks_run << :unfiltered_after_all }
context "a subcontext" do
it("has an example") { }
end
end
filtered_group = ExampleGroup.describe "filtered", :focus => true do
before(:all) { hooks_run << :filtered_before_all }
after(:all) { hooks_run << :filtered_after_all }
context "a subcontext" do
it("has an example") { }
end
end
unfiltered_group.run
filtered_group.run
expect(hooks_run).to eq([:filtered_before_all, :filtered_after_all])
end
it "runs before_all_defined_in_config, before all, before each, example, after each, after all, after_all_defined_in_config in that order" do
order = []
RSpec.configure do |c|
c.before(:all) { order << :before_all_defined_in_config }
c.after(:all) { order << :after_all_defined_in_config }
end
group = ExampleGroup.describe
group.before(:all) { order << :top_level_before_all }
group.before(:each) { order << :before_each }
group.after(:each) { order << :after_each }
group.after(:all) { order << :top_level_after_all }
group.example("top level example") { order << :top_level_example }
context1 = group.describe("context 1")
context1.before(:all) { order << :nested_before_all }
context1.example("nested example 1") { order << :nested_example_1 }
context2 = group.describe("context 2")
context2.after(:all) { order << :nested_after_all }
context2.example("nested example 2") { order << :nested_example_2 }
group.run
expect(order).to eq([
:before_all_defined_in_config,
:top_level_before_all,
:before_each,
:top_level_example,
:after_each,
:nested_before_all,
:before_each,
:nested_example_1,
:after_each,
:before_each,
:nested_example_2,
:after_each,
:nested_after_all,
:top_level_after_all,
:after_all_defined_in_config
])
end
context "after(:all)" do
let(:outer) { ExampleGroup.describe }
let(:inner) { outer.describe }
it "has access to state defined before(:all)" do
outer.before(:all) { @outer = "outer" }
inner.before(:all) { @inner = "inner" }
outer.after(:all) do
expect(@outer).to eq("outer")
expect(@inner).to eq("inner")
end
inner.after(:all) do
expect(@inner).to eq("inner")
expect(@outer).to eq("outer")
end
outer.run
end
it "cleans up ivars in after(:all)" do
outer.before(:all) { @outer = "outer" }
inner.before(:all) { @inner = "inner" }
outer.run
expect(inner.before_all_ivars[:@inner]).to be_nil
expect(inner.before_all_ivars[:@outer]).to be_nil
expect(outer.before_all_ivars[:@inner]).to be_nil
expect(outer.before_all_ivars[:@outer]).to be_nil
end
end
it "treats an error in before(:each) as a failure" do
group = ExampleGroup.describe
group.before(:each) { raise "error in before each" }
example = group.example("equality") { expect(1).to eq(2) }
expect(group.run).to be(false)
expect(example.metadata[:execution_result][:exception].message).to eq("error in before each")
end
it "treats an error in before(:all) as a failure" do
group = ExampleGroup.describe
group.before(:all) { raise "error in before all" }
example = group.example("equality") { expect(1).to eq(2) }
expect(group.run).to be_false
expect(example.metadata).not_to be_nil
expect(example.metadata[:execution_result]).not_to be_nil
expect(example.metadata[:execution_result][:exception]).not_to be_nil
expect(example.metadata[:execution_result][:exception].message).to eq("error in before all")
end
it "exposes instance variables set in before(:all) from after(:all) even if a before(:all) error occurs" do
ivar_value_in_after_hook = nil
group = ExampleGroup.describe do
before(:all) do
@an_ivar = :set_in_before_all
raise "fail"
end
after(:all) { ivar_value_in_after_hook = @an_ivar }
it("has a spec") { }
end
group.run
expect(ivar_value_in_after_hook).to eq(:set_in_before_all)
end
it "treats an error in before(:all) as a failure for a spec in a nested group" do
example = nil
group = ExampleGroup.describe do
before(:all) { raise "error in before all" }
describe "nested" do
example = it("equality") { expect(1).to eq(2) }
end
end
group.run
expect(example.metadata).not_to be_nil
expect(example.metadata[:execution_result]).not_to be_nil
expect(example.metadata[:execution_result][:exception]).not_to be_nil
expect(example.metadata[:execution_result][:exception].message).to eq("error in before all")
end
context "when an error occurs in an after(:all) hook" do
hooks_run = []
before(:each) do
hooks_run = []
RSpec.configuration.reporter.stub(:message)
end
let(:group) do
ExampleGroup.describe do
after(:all) { hooks_run << :one; raise "An error in an after(:all) hook" }
after(:all) { hooks_run << :two; raise "A different hook raising an error" }
it("equality") { expect(1).to eq(1) }
end
end
it "allows the example to pass" do
group.run
example = group.examples.first
expect(example.metadata).not_to be_nil
expect(example.metadata[:execution_result]).not_to be_nil
expect(example.metadata[:execution_result][:status]).to eq("passed")
end
it "rescues any error(s) and prints them out" do
RSpec.configuration.reporter.should_receive(:message).with(/An error in an after\(:all\) hook/)
RSpec.configuration.reporter.should_receive(:message).with(/A different hook raising an error/)
group.run
end
it "still runs both after blocks" do
group.run
expect(hooks_run).to eq [:two,:one]
end
end
it "has no 'running example' within before(:all)" do
group = ExampleGroup.describe
running_example = :none
group.before(:all) { running_example = example }
group.example("no-op") { }
group.run
expect(running_example).to be(nil)
end
it "has access to example options within before(:each)" do
group = ExampleGroup.describe
option = nil
group.before(:each) { option = example.options[:data] }
group.example("no-op", :data => :sample) { }
group.run
expect(option).to eq(:sample)
end
it "has access to example options within after(:each)" do
group = ExampleGroup.describe
option = nil
group.after(:each) { option = example.options[:data] }
group.example("no-op", :data => :sample) { }
group.run
expect(option).to eq(:sample)
end
it "has no 'running example' within after(:all)" do
group = ExampleGroup.describe
running_example = :none
group.after(:all) { running_example = example }
group.example("no-op") { }
group.run
expect(running_example).to be(nil)
end
end
%w[pending xit xspecify xexample].each do |method_name|
describe "::#{method_name}" do
before do
@group = ExampleGroup.describe
@group.send(method_name, "is pending") { }
end
it "generates a pending example" do
@group.run
expect(@group.examples.first).to be_pending
end
it "sets the pending message", :if => method_name == 'pending' do
@group.run
expect(@group.examples.first.metadata[:execution_result][:pending_message]).to eq(RSpec::Core::Pending::NO_REASON_GIVEN)
end
it "sets the pending message", :unless => method_name == 'pending' do
@group.run
expect(@group.examples.first.metadata[:execution_result][:pending_message]).to eq("Temporarily disabled with #{method_name}")
end
end
end
describe "adding examples" do
it "allows adding an example using 'it'" do
group = ExampleGroup.describe
group.it("should do something") { }
expect(group.examples.size).to eq(1)
end
it "exposes all examples at examples" do
group = ExampleGroup.describe
group.it("should do something 1") { }
group.it("should do something 2") { }
group.it("should do something 3") { }
expect(group).to have(3).examples
end
it "maintains the example order" do
group = ExampleGroup.describe
group.it("should 1") { }
group.it("should 2") { }
group.it("should 3") { }
expect(group.examples[0].description).to eq('should 1')
expect(group.examples[1].description).to eq('should 2')
expect(group.examples[2].description).to eq('should 3')
end
end
describe Object, "describing nested example_groups", :little_less_nested => 'yep' do
describe "A sample nested group", :nested_describe => "yep" do
it "sets the described class to the described class of the outer most group" do
expect(example.example_group.described_class).to eq(ExampleGroup)
end
it "sets the description to 'A sample nested describe'" do
expect(example.example_group.description).to eq('A sample nested group')
end
it "has top level metadata from the example_group and its parent groups" do
expect(example.example_group.metadata).to include(:little_less_nested => 'yep', :nested_describe => 'yep')
end
it "exposes the parent metadata to the contained examples" do
expect(example.metadata).to include(:little_less_nested => 'yep', :nested_describe => 'yep')
end
end
end
describe "#run_examples" do
let(:reporter) { double("reporter").as_null_object }
it "returns true if all examples pass" do
group = ExampleGroup.describe('group') do
example('ex 1') { expect(1).to eq(1) }
example('ex 2') { expect(1).to eq(1) }
end
group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered::Examples) }
expect(group.run(reporter)).to be_true
end
it "returns false if any of the examples fail" do
group = ExampleGroup.describe('group') do
example('ex 1') { expect(1).to eq(1) }
example('ex 2') { expect(1).to eq(2) }
end
group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered::Examples) }
expect(group.run(reporter)).to be_false
end
it "runs all examples, regardless of any of them failing" do
group = ExampleGroup.describe('group') do
example('ex 1') { expect(1).to eq(2) }
example('ex 2') { expect(1).to eq(1) }
end
group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered::Examples) }
group.filtered_examples.each do |example|
example.should_receive(:run)
end
expect(group.run(reporter)).to be_false
end
end
describe "how instance variables are inherited" do
before(:all) do
@before_all_top_level = 'before_all_top_level'
end
before(:each) do
@before_each_top_level = 'before_each_top_level'
end
it "can access a before each ivar at the same level" do
expect(@before_each_top_level).to eq('before_each_top_level')
end
it "can access a before all ivar at the same level" do
expect(@before_all_top_level).to eq('before_all_top_level')
end
it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.8 do
expect(example.example_group.before_all_ivars).to include('@before_all_top_level' => 'before_all_top_level')
end
it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.9 do
expect(example.example_group.before_all_ivars).to include(:@before_all_top_level => 'before_all_top_level')
end
describe "but now I am nested" do
it "can access a parent example groups before each ivar at a nested level" do
expect(@before_each_top_level).to eq('before_each_top_level')
end
it "can access a parent example groups before all ivar at a nested level" do
expect(@before_all_top_level).to eq("before_all_top_level")
end
it "changes to before all ivars from within an example do not persist outside the current describe" do
@before_all_top_level = "ive been changed"
end
describe "accessing a before_all ivar that was changed in a parent example_group" do
it "does not have access to the modified version" do
expect(@before_all_top_level).to eq('before_all_top_level')
end
end
end
end
describe "ivars are not shared across examples" do
it "(first example)" do
@a = 1
expect(defined?(@b)).to be_false
end
it "(second example)" do
@b = 2
expect(defined?(@a)).to be_false
end
end
describe "#top_level_description" do
it "returns the description from the outermost example group" do
group = nil
ExampleGroup.describe("top") do
context "middle" do
group = describe "bottom" do
end
end
end
expect(group.top_level_description).to eq("top")
end
end
describe "#run" do
let(:reporter) { double("reporter").as_null_object }
context "with fail_fast? => true" do
let(:group) do
group = RSpec::Core::ExampleGroup.describe
group.stub(:fail_fast?) { true }
group
end
it "does not run examples after the failed example" do
examples_run = []
group.example('example 1') { examples_run << self }
group.example('example 2') { examples_run << self; fail; }
group.example('example 3') { examples_run << self }
group.run
expect(examples_run.length).to eq(2)
end
it "sets RSpec.wants_to_quit flag if encountering an exception in before(:all)" do
group.before(:all) { raise "error in before all" }
group.example("equality") { expect(1).to eq(2) }
expect(group.run).to be_false
expect(RSpec.wants_to_quit).to be_true
end
end
context "with RSpec.wants_to_quit=true" do
let(:group) { RSpec::Core::ExampleGroup.describe }
before do
RSpec.stub(:wants_to_quit) { true }
RSpec.stub(:clear_remaining_example_groups)
end
it "returns without starting the group" do
reporter.should_not_receive(:example_group_started)
group.run(reporter)
end
context "at top level" do
it "purges remaining groups" do
RSpec.should_receive(:clear_remaining_example_groups)
group.run(reporter)
end
end
context "in a nested group" do
it "does not purge remaining groups" do
nested_group = group.describe
RSpec.should_not_receive(:clear_remaining_example_groups)
nested_group.run(reporter)
end
end
end
context "with all examples passing" do
it "returns true" do
group = RSpec::Core::ExampleGroup.describe("something") do
it "does something" do
# pass
end
describe "nested" do
it "does something else" do
# pass
end
end
end
expect(group.run(reporter)).to be_true
end
end
context "with top level example failing" do
it "returns false" do
group = RSpec::Core::ExampleGroup.describe("something") do
it "does something (wrong - fail)" do
raise "fail"
end
describe "nested" do
it "does something else" do
# pass
end
end
end
expect(group.run(reporter)).to be_false
end
end
context "with nested example failing" do
it "returns true" do
group = RSpec::Core::ExampleGroup.describe("something") do
it "does something" do
# pass
end
describe "nested" do
it "does something else (wrong -fail)" do
raise "fail"
end
end
end
expect(group.run(reporter)).to be_false
end
end
end
%w[include_examples include_context].each do |name|
describe "##{name}" do
let(:group) { ExampleGroup.describe }
before do
group.shared_examples "named this" do
example("does something") {}
end
end
it "includes the named examples" do
group.send(name, "named this")
expect(group.examples.first.description).to eq("does something")
end
it "raises a helpful error message when shared content is not found" do
expect do
group.send(name, "shared stuff")
end.to raise_error(ArgumentError, /Could not find .* "shared stuff"/)
end
it "passes parameters to the shared content" do
passed_params = {}
group = ExampleGroup.describe
group.shared_examples "named this with params" do |param1, param2|
it("has access to the given parameters") do
passed_params[:param1] = param1
passed_params[:param2] = param2
end
end
group.send(name, "named this with params", :value1, :value2)
group.run
expect(passed_params).to eq({ :param1 => :value1, :param2 => :value2 })
end
it "adds shared instance methods to the group" do
group = ExampleGroup.describe('fake group')
group.shared_examples "named this with params" do |param1|
def foo; end
end
group.send(name, "named this with params", :a)
expect(group.public_instance_methods.map{|m| m.to_s}).to include("foo")
end
it "evals the shared example group only once" do
eval_count = 0
group = ExampleGroup.describe('fake group')
group.shared_examples("named this with params") { |p| eval_count += 1 }
group.send(name, "named this with params", :a)
expect(eval_count).to eq(1)
end
it "evals the block when given" do
key = "#{__FILE__}:#{__LINE__}"
group = ExampleGroup.describe do
shared_examples(key) do
it("does something") do
expect(foo).to eq("bar")
end
end
send name, key do
def foo; "bar"; end
end
end
expect(group.run).to be_true
end
end
end
describe "#it_should_behave_like" do
it "creates a nested group" do
group = ExampleGroup.describe('fake group')
group.shared_examples_for("thing") {}
group.it_should_behave_like("thing")
expect(group).to have(1).children
end
it "creates a nested group for a class" do
klass = Class.new
group = ExampleGroup.describe('fake group')
group.shared_examples_for(klass) {}
group.it_should_behave_like(klass)
expect(group).to have(1).children
end
it "adds shared examples to nested group" do
group = ExampleGroup.describe('fake group')
group.shared_examples_for("thing") do
it("does something")
end
shared_group = group.it_should_behave_like("thing")
expect(shared_group).to have(1).examples
end
it "adds shared instance methods to nested group" do
group = ExampleGroup.describe('fake group')
group.shared_examples_for("thing") do
def foo; end
end
shared_group = group.it_should_behave_like("thing")
expect(shared_group.public_instance_methods.map{|m| m.to_s}).to include("foo")
end
it "adds shared class methods to nested group" do
group = ExampleGroup.describe('fake group')
group.shared_examples_for("thing") do
def self.foo; end
end
shared_group = group.it_should_behave_like("thing")
expect(shared_group.methods.map{|m| m.to_s}).to include("foo")
end
it "passes parameters to the shared example group" do
passed_params = {}
group = ExampleGroup.describe("group") do
shared_examples_for("thing") do |param1, param2|
it("has access to the given parameters") do
passed_params[:param1] = param1
passed_params[:param2] = param2
end
end
it_should_behave_like "thing", :value1, :value2
end
group.run
expect(passed_params).to eq({ :param1 => :value1, :param2 => :value2 })
end
it "adds shared instance methods to nested group" do
group = ExampleGroup.describe('fake group')
group.shared_examples_for("thing") do |param1|
def foo; end
end
shared_group = group.it_should_behave_like("thing", :a)
expect(shared_group.public_instance_methods.map{|m| m.to_s}).to include("foo")
end
it "evals the shared example group only once" do
eval_count = 0
group = ExampleGroup.describe('fake group')
group.shared_examples_for("thing") { |p| eval_count += 1 }
group.it_should_behave_like("thing", :a)
expect(eval_count).to eq(1)
end
context "given a block" do
it "evaluates the block in nested group" do
scopes = []
group = ExampleGroup.describe("group") do
shared_examples_for("thing") do
it("gets run in the nested group") do
scopes << self.class
end
end
it_should_behave_like "thing" do
it("gets run in the same nested group") do
scopes << self.class
end
end
end
group.run
expect(scopes[0]).to be(scopes[1])
end
end
it "raises a helpful error message when shared context is not found" do
expect do
ExampleGroup.describe do
it_should_behave_like "shared stuff"
end
end.to raise_error(ArgumentError,%q|Could not find shared examples "shared stuff"|)
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/drb_command_line_spec.rb 0000644 0000041 0000041 00000005572 12261207027 023520 0 ustar www-data www-data require "spec_helper"
require 'rspec/core/drb_command_line'
describe "::DRbCommandLine", :type => :drb, :unless => RUBY_PLATFORM == 'java' do
let(:config) { RSpec::Core::Configuration.new }
let(:out) { StringIO.new }
let(:err) { StringIO.new }
include_context "spec files"
def command_line(*args)
RSpec::Core::DRbCommandLine.new(config_options(*args))
end
def config_options(*args)
options = RSpec::Core::ConfigurationOptions.new(args)
options.parse_options
options
end
context "without server running" do
it "raises an error" do
expect { command_line.run(err, out) }.to raise_error(DRb::DRbConnError)
end
end
describe "--drb-port" do
def with_RSPEC_DRB_set_to(val)
with_env_vars('RSPEC_DRB' => val) { yield }
end
context "without RSPEC_DRB environment variable set" do
it "defaults to 8989" do
with_RSPEC_DRB_set_to(nil) do
expect(command_line.drb_port).to eq(8989)
end
end
it "sets the DRb port" do
with_RSPEC_DRB_set_to(nil) do
expect(command_line("--drb-port", "1234").drb_port).to eq(1234)
expect(command_line("--drb-port", "5678").drb_port).to eq(5678)
end
end
end
context "with RSPEC_DRB environment variable set" do
context "without config variable set" do
it "uses RSPEC_DRB value" do
with_RSPEC_DRB_set_to('9000') do
expect(command_line.drb_port).to eq("9000")
end
end
end
context "and config variable set" do
it "uses configured value" do
with_RSPEC_DRB_set_to('9000') do
expect(command_line(*%w[--drb-port 5678]).drb_port).to eq(5678)
end
end
end
end
end
context "with server running" do
class SimpleDRbSpecServer
def self.run(argv, err, out)
options = RSpec::Core::ConfigurationOptions.new(argv)
options.parse_options
RSpec::Core::CommandLine.new(options, RSpec::Core::Configuration.new).run(err, out)
end
end
before(:all) do
@drb_port = '8990'
@drb_example_file_counter = 0
DRb::start_service("druby://127.0.0.1:#{@drb_port}", SimpleDRbSpecServer)
end
after(:all) do
DRb::stop_service
end
it "returns 0 if spec passes" do
result = command_line("--drb-port", @drb_port, passing_spec_filename).run(err, out)
expect(result).to be(0)
end
it "returns 1 if spec fails" do
result = command_line("--drb-port", @drb_port, failing_spec_filename).run(err, out)
expect(result).to be(1)
end
it "outputs colorized text when running with --colour option" do
pending "figure out a way to tell the output to say it's tty"
command_line(failing_spec_filename, "--color", "--drb-port", @drb_port).run(err, out)
out.rewind
expect(out.read).to match(/\e\[31m/m)
end
end
end
rspec-core-2.14.7/spec/rspec/core/command_line_spec.rb 0000644 0000041 0000041 00000006672 12261207027 022673 0 ustar www-data www-data require "spec_helper"
require "stringio"
require 'tmpdir'
module RSpec::Core
describe CommandLine do
let(:out) { StringIO.new }
let(:err) { StringIO.new }
let(:config) { RSpec::configuration }
let(:world) { RSpec::world }
before { config.stub :run_hook }
it "configures streams before command line options" do
config.stub :load_spec_files
# this is necessary to ensure that color works correctly on windows
config.should_receive(:error_stream=).ordered
config.should_receive(:output_stream=).ordered
config.should_receive(:force).at_least(:once).ordered
command_line = build_command_line
command_line.run err, out
end
it "assigns ConfigurationOptions built from Array of options to @options" do
config_options = ConfigurationOptions.new(%w[--color])
command_line = CommandLine.new(%w[--color])
expect(command_line.instance_eval { @options.options }).to eq(config_options.parse_options)
end
it "assigns submitted ConfigurationOptions to @options" do
config_options = ConfigurationOptions.new(%w[--color])
command_line = CommandLine.new(config_options)
expect(command_line.instance_eval { @options }).to be(config_options)
end
describe "#run" do
context "running files" do
include_context "spec files"
it "returns 0 if spec passes" do
command_line = build_command_line passing_spec_filename
expect(command_line.run(err, out)).to eq 0
end
it "returns 1 if spec fails" do
command_line = build_command_line failing_spec_filename
expect(command_line.run(err, out)).to eq 1
end
it "returns 2 if spec fails and --failure-exit-code is 2" do
command_line = build_command_line failing_spec_filename, "--failure-exit-code", "2"
expect(command_line.run(err, out)).to eq 2
end
end
context "running hooks" do
before { config.stub :load_spec_files }
it "runs before suite hooks" do
config.should_receive(:run_hook).with(:before, :suite)
command_line = build_command_line
command_line.run err, out
end
it "runs after suite hooks" do
config.should_receive(:run_hook).with(:after, :suite)
command_line = build_command_line
command_line.run err, out
end
it "runs after suite hooks even after an error" do
config.should_receive(:run_hook).with(:before, :suite).and_raise "this error"
config.should_receive(:run_hook).with(:after , :suite)
expect do
command_line = build_command_line
command_line.run err, out
end.to raise_error
end
end
end
describe "#run with custom output" do
before { config.stub :files_to_run => [] }
let(:output_file) { File.new("#{Dir.tmpdir}/command_line_spec_output.txt", 'w') }
it "doesn't override output_stream" do
config.output_stream = output_file
command_line = build_command_line
command_line.run err, out
expect(command_line.instance_eval { @configuration.output_stream }).to eq output_file
end
end
def build_command_line *args
CommandLine.new build_config_options(*args)
end
def build_config_options *args
options = ConfigurationOptions.new args
options.parse_options
options
end
end
end
rspec-core-2.14.7/spec/rspec/core/ruby_project_spec.rb 0000644 0000041 0000041 00000001276 12261207027 022750 0 ustar www-data www-data require 'spec_helper'
module RSpec
module Core
describe RubyProject do
describe "#determine_root" do
context "with ancestor containing spec directory" do
it "returns ancestor containing the spec directory" do
RubyProject.stub(:ascend_until).and_return('foodir')
expect(RubyProject.determine_root).to eq("foodir")
end
end
context "without ancestor containing spec directory" do
it "returns current working directory" do
RubyProject.stub(:find_first_parent_containing).and_return(nil)
expect(RubyProject.determine_root).to eq(".")
end
end
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/hooks_spec.rb 0000644 0000041 0000041 00000020700 12261207027 021355 0 ustar www-data www-data require "spec_helper"
module RSpec::Core
describe Hooks do
class HooksHost
include Hooks
end
[:before, :after, :around].each do |type|
[:each, :all].each do |scope|
next if type == :around && scope == :all
describe "##{type}(#{scope})" do
it_behaves_like "metadata hash builder" do
define_method :metadata_hash do |*args|
instance = HooksHost.new
args.unshift scope if scope
hooks = instance.send(type, *args) {}
hooks.first.options
end
end
end
end
[true, false].each do |config_value|
context "when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to #{config_value}" do
before(:each) do
Kernel.stub(:warn)
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = config_value }
end
describe "##{type}(no scope)" do
let(:instance) { HooksHost.new }
it "defaults to :each scope if no arguments are given" do
hooks = instance.send(type) {}
hook = hooks.first
expect(instance.hooks[type][:each]).to include(hook)
end
it "defaults to :each scope if the only argument is a metadata hash" do
hooks = instance.send(type, :foo => :bar) {}
hook = hooks.first
expect(instance.hooks[type][:each]).to include(hook)
end
it "raises an error if only metadata symbols are given as arguments" do
expect { instance.send(type, :foo, :bar) {} }.to raise_error(ArgumentError)
end
end
end
end
end
[:before, :after].each do |type|
[:each, :all, :suite].each do |scope|
[true, false].each do |config_value|
context "when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to #{config_value}" do
before(:each) do
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = config_value }
end
describe "##{type}(#{scope.inspect})" do
let(:instance) { HooksHost.new }
let!(:hook) do
hooks = instance.send(type, scope) {}
hooks.first
end
it "does not make #{scope.inspect} a metadata key" do
expect(hook.options).to be_empty
end
it "is scoped to #{scope.inspect}" do
expect(instance.hooks[type][scope]).to include(hook)
end
end
end
end
end
end
describe "#around" do
context "when not running the example within the around block" do
it "does not run the example" do
examples = []
group = ExampleGroup.describe do
around do |example|
end
it "foo" do
examples << self
end
end
group.run
expect(examples).to have(0).example
end
end
context "when running the example within the around block" do
it "runs the example" do
examples = []
group = ExampleGroup.describe do
around do |example|
example.run
end
it "foo" do
examples << self
end
end
group.run
expect(examples).to have(1).example
end
end
context "when running the example within a block passed to a method" do
it "runs the example" do
examples = []
group = ExampleGroup.describe do
def yielder
yield
end
around do |example|
yielder { example.run }
end
it "foo" do
examples << self
end
end
group.run
expect(examples).to have(1).example
end
end
end
[:all, :each].each do |scope|
describe "prepend_before(#{scope})" do
it "adds to the front of the list of before(:#{scope}) hooks" do
messages = []
RSpec.configure { |config| config.before(scope) { messages << "config 3" } }
RSpec.configure { |config| config.prepend_before(scope) { messages << "config 2" } }
RSpec.configure { |config| config.before(scope) { messages << "config 4" } }
RSpec.configure { |config| config.prepend_before(scope) { messages << "config 1" } }
group = ExampleGroup.describe { example {} }
group.before(scope) { messages << "group 3" }
group.prepend_before(scope) { messages << "group 2" }
group.before(scope) { messages << "group 4" }
group.prepend_before(scope) { messages << "group 1" }
group.run
expect(messages).to eq([
'group 1',
'group 2',
'config 1',
'config 2',
'config 3',
'config 4',
'group 3',
'group 4'
])
end
end
describe "append_before(#{scope})" do
it "adds to the back of the list of before(:#{scope}) hooks (same as `before`)" do
messages = []
RSpec.configure { |config| config.before(scope) { messages << "config 1" } }
RSpec.configure { |config| config.append_before(scope) { messages << "config 2" } }
RSpec.configure { |config| config.before(scope) { messages << "config 3" } }
group = ExampleGroup.describe { example {} }
group.before(scope) { messages << "group 1" }
group.append_before(scope) { messages << "group 2" }
group.before(scope) { messages << "group 3" }
group.run
expect(messages).to eq([
'config 1',
'config 2',
'config 3',
'group 1',
'group 2',
'group 3'
])
end
end
describe "prepend_after(#{scope})" do
it "adds to the front of the list of after(:#{scope}) hooks (same as `after`)" do
messages = []
RSpec.configure { |config| config.after(scope) { messages << "config 3" } }
RSpec.configure { |config| config.prepend_after(scope) { messages << "config 2" } }
RSpec.configure { |config| config.after(scope) { messages << "config 1" } }
group = ExampleGroup.describe { example {} }
group.after(scope) { messages << "group 3" }
group.prepend_after(scope) { messages << "group 2" }
group.after(scope) { messages << "group 1" }
group.run
expect(messages).to eq([
'group 1',
'group 2',
'group 3',
'config 1',
'config 2',
'config 3'
])
end
end
describe "append_after(#{scope})" do
it "adds to the back of the list of after(:#{scope}) hooks" do
messages = []
RSpec.configure { |config| config.after(scope) { messages << "config 2" } }
RSpec.configure { |config| config.append_after(scope) { messages << "config 3" } }
RSpec.configure { |config| config.after(scope) { messages << "config 1" } }
RSpec.configure { |config| config.append_after(scope) { messages << "config 4" } }
group = ExampleGroup.describe { example {} }
group.after(scope) { messages << "group 2" }
group.append_after(scope) { messages << "group 3" }
group.after(scope) { messages << "group 1" }
group.append_after(scope) { messages << "group 4" }
group.run
expect(messages).to eq([
'group 1',
'group 2',
'config 1',
'config 2',
'config 3',
'config 4',
'group 3',
'group 4'
])
end
end
end
describe "lambda" do
it "can be used as a hook" do
messages = []
count = 0
hook = lambda {|e| messages << "hook #{count = count + 1}"; e.run }
RSpec.configure do |c|
c.around(:each, &hook)
c.around(:each, &hook)
end
group = ExampleGroup.describe { example { messages << "example" } }
group.run
expect(messages).to eq ["hook 1", "hook 2", "example"]
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/memoized_helpers_spec.rb 0000644 0000041 0000041 00000046060 12261207027 023574 0 ustar www-data www-data require 'spec_helper'
module RSpec::Core
describe MemoizedHelpers do
before(:each) { RSpec.configuration.configure_expectation_framework }
def subject_value_for(describe_arg, &block)
group = ExampleGroup.describe(describe_arg, &block)
subject_value = nil
group.example { subject_value = subject }
group.run
subject_value
end
describe "implicit subject" do
describe "with a class" do
it "returns an instance of the class" do
expect(subject_value_for(Array)).to eq([])
end
end
describe "with a Module" do
it "returns the Module" do
expect(subject_value_for(Enumerable)).to eq(Enumerable)
end
end
describe "with a string" do
it "returns the string" do
expect(subject_value_for("Foo")).to eq("Foo")
end
end
describe "with a number" do
it "returns the number" do
expect(subject_value_for(15)).to eq(15)
end
end
it "can be overriden and super'd to from a nested group" do
outer_subject_value = inner_subject_value = nil
ExampleGroup.describe(Array) do
subject { super() << :parent_group }
example { outer_subject_value = subject }
context "nested" do
subject { super() << :child_group }
example { inner_subject_value = subject }
end
end.run
expect(outer_subject_value).to eq([:parent_group])
expect(inner_subject_value).to eq([:parent_group, :child_group])
end
end
describe "explicit subject" do
[false, nil].each do |falsy_value|
context "with a value of #{falsy_value.inspect}" do
it "is evaluated once per example" do
group = ExampleGroup.describe(Array)
group.before do
Object.should_receive(:this_question?).once.and_return(falsy_value)
end
group.subject do
Object.this_question?
end
group.example do
subject
subject
end
expect(group.run).to be_true, "expected subject block to be evaluated only once"
end
end
end
describe "defined in a top level group" do
it "replaces the implicit subject in that group" do
subject_value = subject_value_for(Array) do
subject { [1, 2, 3] }
end
expect(subject_value).to eq([1, 2, 3])
end
end
describe "defined in a top level group" do
let(:group) do
ExampleGroup.describe do
subject{ [4, 5, 6] }
end
end
it "is available in a nested group (subclass)" do
subject_value = nil
group.describe("I'm nested!") do
example { subject_value = subject }
end.run
expect(subject_value).to eq([4, 5, 6])
end
it "is available in a doubly nested group (subclass)" do
subject_value = nil
group.describe("Nesting level 1") do
describe("Nesting level 2") do
example { subject_value = subject }
end
end.run
expect(subject_value).to eq([4, 5, 6])
end
it "can be overriden and super'd to from a nested group" do
subject_value = nil
group.describe("Nested") do
subject { super() + [:override] }
example { subject_value = subject }
end.run
expect(subject_value).to eq([4, 5, 6, :override])
end
context 'when referenced in a `before(:all)` hook' do
before do
expect(::RSpec).to respond_to(:warn_deprecation)
::RSpec.stub(:warn_deprecation)
end
def define_and_run_group
values = { :reference_lines => [] }
ExampleGroup.describe do
subject { [1, 2] }
let(:list) { %w[ a b ] }
before(:all) do
subject << 3; values[:reference_lines] << __LINE__
values[:final_subject_value_in_before_all] = subject; values[:reference_lines] << __LINE__
end
example do
list << '1'
values[:list_in_ex_1] = list
values[:subject_value_in_example] = subject
end
example do
list << '2'
values[:list_in_ex_2] = list
end
end.run
values
end
it 'memoizes the value within the before(:all) hook' do
values = define_and_run_group
expect(values.fetch(:final_subject_value_in_before_all)).to eq([1, 2, 3])
end
it 'preserves the memoization into the individual examples' do
values = define_and_run_group
expect(values.fetch(:subject_value_in_example)).to eq([1, 2, 3])
end
it 'does not cause other lets to be shared across examples' do
values = define_and_run_group
expect(values.fetch(:list_in_ex_1)).to eq(%w[ a b 1 ])
expect(values.fetch(:list_in_ex_2)).to eq(%w[ a b 2 ])
end
it 'prints a warning since `subject` declarations are not intended to be used in :all hooks' do
msgs = []
::RSpec.stub(:warn_deprecation) { |msg| msgs << msg }
values = define_and_run_group
expect(msgs).to include(*values[:reference_lines].map { |line|
match(/subject accessed.*#{__FILE__}:#{line}/m)
})
end
end
end
describe "with a name" do
it "defines a method that returns the memoized subject" do
list_value_1 = list_value_2 = subject_value_1 = subject_value_2 = nil
ExampleGroup.describe do
subject(:list) { [1, 2, 3] }
example do
list_value_1 = list
list_value_2 = list
subject_value_1 = subject
subject_value_2 = subject
end
end.run
expect(list_value_1).to eq([1, 2, 3])
expect(list_value_1).to equal(list_value_2)
expect(subject_value_1).to equal(subject_value_2)
expect(subject_value_1).to equal(list_value_1)
end
it "is referred from inside subject by the name" do
inner_subject_value = nil
ExampleGroup.describe do
subject(:list) { [1, 2, 3] }
describe 'first' do
subject(:first_element) { list.first }
example { inner_subject_value = subject }
end
end.run
expect(inner_subject_value).to eq(1)
end
it 'can continue to be referenced by the name even when an inner group redefines the subject' do
named_value = nil
ExampleGroup.describe do
subject(:named) { :outer }
describe "inner" do
subject { :inner }
example do
subject # so the inner subject method is run and memoized
named_value = self.named
end
end
end.run
expect(named_value).to eq(:outer)
end
it 'can continue to reference an inner subject after the outer subject name is referenced' do
subject_value = nil
ExampleGroup.describe do
subject(:named) { :outer }
describe "inner" do
subject { :inner }
example do
named # so the outer subject method is run and memoized
subject_value = self.subject
end
end
end.run
expect(subject_value).to eq(:inner)
end
it 'is not overriden when an inner group defines a new method with the same name' do
subject_value = nil
ExampleGroup.describe do
subject(:named) { :outer_subject }
describe "inner" do
let(:named) { :inner_named }
example { subject_value = self.subject }
end
end.run
expect(subject_value).to be(:outer_subject)
end
context 'when `super` is used' do
def should_raise_not_supported_error(&block)
ex = nil
ExampleGroup.describe do
let(:list) { ["a", "b", "c"] }
subject { [1, 2, 3] }
describe 'first' do
module_eval(&block) if block
subject(:list) { super().first(2) }
ex = example { subject }
end
end.run
expect(ex.execution_result[:status]).to eq("failed")
expect(ex.execution_result[:exception].message).to match(/super.*not supported/)
end
it 'raises a "not supported" error' do
should_raise_not_supported_error
end
context 'with a `let` definition before the named subject' do
it 'raises a "not supported" error' do
should_raise_not_supported_error do
# My first pass implementation worked unless there was a `let`
# declared before the named subject -- this let is in place to
# ensure that bug doesn't return.
let(:foo) { 3 }
end
end
end
end
end
end
context "using 'self' as an explicit subject" do
it "delegates matcher to the ExampleGroup" do
group = ExampleGroup.describe("group") do
subject { self }
def ok?; true; end
def not_ok?; false; end
it { should eq(self) }
it { should be_ok }
it { should_not be_not_ok }
end
expect(group.run).to be_true
end
end
describe "#its" do
subject do
Class.new do
def initialize
@call_count = 0
end
def call_count
@call_count += 1
end
end.new
end
context "with a call counter" do
its(:call_count) { should eq(1) }
end
context "with nil value" do
subject do
Class.new do
def nil_value
nil
end
end.new
end
its(:nil_value) { should be_nil }
end
context "with nested attributes" do
subject do
Class.new do
def name
"John"
end
end.new
end
its("name") { should eq("John") }
its("name.size") { should eq(4) }
its("name.size.class") { should eq(Fixnum) }
end
context "when it responds to #[]" do
subject do
Class.new do
def [](*objects)
objects.map do |object|
"#{object.class}: #{object.to_s}"
end.join("; ")
end
def name
"George"
end
end.new
end
its([:a]) { should eq("Symbol: a") }
its(['a']) { should eq("String: a") }
its([:b, 'c', 4]) { should eq("Symbol: b; String: c; Fixnum: 4") }
its(:name) { should eq("George") }
context "when referring to an attribute without the proper array syntax" do
context "it raises an error" do
its(:age) do
expect do
should eq(64)
end.to raise_error(NoMethodError)
end
end
end
end
context "when it does not respond to #[]" do
subject { Object.new }
context "it raises an error" do
its([:a]) do
expect do
should eq("Symbol: a")
end.to raise_error(NoMethodError)
end
end
end
context "calling and overriding super" do
it "calls to the subject defined in the parent group" do
group = ExampleGroup.describe(Array) do
subject { [1, 'a'] }
its(:last) { should eq("a") }
describe '.first' do
def subject; super().first; end
its(:next) { should eq(2) }
end
end
expect(group.run).to be_true
end
end
context "with nil subject" do
subject do
Class.new do
def initialize
@counter = -1
end
def nil_if_first_time
@counter += 1
@counter == 0 ? nil : true
end
end.new
end
its(:nil_if_first_time) { should be(nil) }
end
context "with false subject" do
subject do
Class.new do
def initialize
@counter = -1
end
def false_if_first_time
@counter += 1
@counter > 0
end
end.new
end
its(:false_if_first_time) { should be(false) }
end
describe 'accessing `subject` in `before` and `let`' do
subject { 'my subject' }
before { @subject_in_before = subject }
let(:subject_in_let) { subject }
let!(:eager_loaded_subject_in_let) { subject }
# These examples read weird, because we're actually
# specifying the behaviour of `its` itself
its(nil) { expect(subject).to eq('my subject') }
its(nil) { expect(@subject_in_before).to eq('my subject') }
its(nil) { expect(subject_in_let).to eq('my subject') }
its(nil) { expect(eager_loaded_subject_in_let).to eq('my subject') }
end
end
describe '#subject!' do
let(:prepared_array) { [1,2,3] }
subject! { prepared_array.pop }
it "evaluates subject before example" do
expect(prepared_array).to eq([1,2])
end
it "returns memoized value from first invocation" do
expect(subject).to eq(3)
end
end
end
describe "#let" do
let(:counter) do
Class.new do
def initialize
@count = 0
end
def count
@count += 1
end
end.new
end
let(:nil_value) do
@nil_value_count += 1
nil
end
it "generates an instance method" do
expect(counter.count).to eq(1)
end
it "caches the value" do
expect(counter.count).to eq(1)
expect(counter.count).to eq(2)
end
it "caches a nil value" do
@nil_value_count = 0
nil_value
nil_value
expect(@nil_value_count).to eq(1)
end
let(:regex_with_capture) { %r[RegexWithCapture(\d)] }
it 'does not pass the block up the ancestor chain' do
# Test for Ruby bug http://bugs.ruby-lang.org/issues/8059
expect("RegexWithCapture1".match(regex_with_capture)[1]).to eq('1')
end
it 'raises a useful error when called without a block' do
expect do
ExampleGroup.describe { let(:list) }
end.to raise_error(/#let or #subject called without a block/)
end
let(:a_value) { "a string" }
context 'when overriding let in a nested context' do
let(:a_value) { super() + " (modified)" }
it 'can use `super` to reference the parent context value' do
expect(a_value).to eq("a string (modified)")
end
end
context 'when the declaration uses `return`' do
let(:value) do
return :early_exit if @early_exit
:late_exit
end
it 'can exit the let declaration early' do
@early_exit = true
expect(value).to eq(:early_exit)
end
it 'can get past a conditional `return` statement' do
@early_exit = false
expect(value).to eq(:late_exit)
end
end
context 'when referenced in a `before(:all)` hook' do
before do
expect(::RSpec).to respond_to(:warn_deprecation)
::RSpec.stub(:warn_deprecation)
end
def define_and_run_group
values = { :reference_lines => [] }
ExampleGroup.describe do
let(:list) { [1, 2] }
subject { %w[ a b ] }
before(:all) do
list << 3; values[:reference_lines] << __LINE__
values[:final_list_value_in_before_all] = list; values[:reference_lines] << __LINE__
end
example do
subject << "1"
values[:subject_in_ex_1] = subject
values[:list_value_in_example] = list
end
example do
subject << "2"
values[:subject_in_ex_2] = subject
end
end.run
values
end
it 'memoizes the value within the before(:all) hook' do
values = define_and_run_group
expect(values.fetch(:final_list_value_in_before_all)).to eq([1, 2, 3])
end
it 'preserves the memoized value into the examples' do
values = define_and_run_group
expect(values.fetch(:list_value_in_example)).to eq([1, 2, 3])
end
it 'does not cause the subject to be shared across examples' do
values = define_and_run_group
expect(values.fetch(:subject_in_ex_1)).to eq(%w[ a b 1 ])
expect(values.fetch(:subject_in_ex_2)).to eq(%w[ a b 2 ])
end
it 'prints a warning since `let` declarations are not intended to be used in :all hooks' do
msgs = []
::RSpec.stub(:warn_deprecation) { |msg| msgs << msg }
values = define_and_run_group
expect(msgs).to include(*values[:reference_lines].map { |line|
match(/let declaration `list` accessed.*#{__FILE__}:#{line}/m)
})
end
end
context "when included modules have hooks that define memoized helpers" do
it "allows memoized helpers to override methods in previously included modules" do
group = ExampleGroup.describe do
include Module.new {
def self.included(m); m.let(:unrelated) { :unrelated }; end
}
include Module.new {
def hello_message; "Hello from module"; end
}
let(:hello_message) { "Hello from let" }
end
expect(group.new.hello_message).to eq("Hello from let")
end
end
end
describe "#let!" do
subject { [1,2,3] }
let!(:popped) { subject.pop }
it "evaluates the value non-lazily" do
expect(subject).to eq([1,2])
end
it "returns memoized value from first invocation" do
expect(popped).to eq(3)
end
end
describe 'using subject in before and let blocks' do
shared_examples_for 'a subject' do
let(:subject_id_in_let) { subject.object_id }
before { @subject_id_in_before = subject.object_id }
it 'should be memoized' do
expect(subject_id_in_let).to eq(@subject_id_in_before)
end
it { should eq(subject) }
end
describe Object do
context 'with implicit subject' do
it_should_behave_like 'a subject'
end
context 'with explicit subject' do
subject { Object.new }
it_should_behave_like 'a subject'
end
context 'with a constant subject'do
subject { 123 }
it_should_behave_like 'a subject'
end
end
end
describe 'Module#define_method' do
it 'is still a private method' do
a_module = Module.new
expect { a_module.define_method(:name) { "implementation" } }.to raise_error NoMethodError
end
end
end
rspec-core-2.14.7/spec/rspec/core/dsl_spec.rb 0000644 0000041 0000041 00000001006 12261207027 021012 0 ustar www-data www-data require 'spec_helper'
main = self
describe "The RSpec DSL" do
methods = [
:describe,
:share_examples_for,
:shared_examples_for,
:shared_examples,
:shared_context,
:share_as
]
methods.each do |method_name|
describe "##{method_name}" do
it "is not added to every object in the system" do
expect(main).to respond_to(method_name)
expect(Module.new).to respond_to(method_name)
expect(Object.new).not_to respond_to(method_name)
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/runner_spec.rb 0000644 0000041 0000041 00000005261 12261207027 021550 0 ustar www-data www-data require 'spec_helper'
require 'rspec/core/drb_command_line'
module RSpec::Core
describe Runner do
describe 'at_exit' do
it 'sets an at_exit hook if none is already set' do
RSpec::Core::Runner.stub(:installed_at_exit?).and_return(false)
RSpec::Core::Runner.stub(:running_in_drb?).and_return(false)
RSpec::Core::Runner.stub(:at_exit_hook_disabled?).and_return(false)
RSpec::Core::Runner.stub(:run).and_return(-1)
RSpec::Core::Runner.should_receive(:at_exit)
RSpec::Core::Runner.autorun
end
it 'does not set the at_exit hook if it is already set' do
RSpec::Core::Runner.stub(:installed_at_exit?).and_return(true)
RSpec::Core::Runner.stub(:running_in_drb?).and_return(false)
RSpec::Core::Runner.stub(:at_exit_hook_disabled?).and_return(false)
RSpec::Core::Runner.should_receive(:at_exit).never
RSpec::Core::Runner.autorun
end
end
describe "#run" do
let(:err) { StringIO.new }
let(:out) { StringIO.new }
it "tells RSpec to reset" do
RSpec.configuration.stub(:files_to_run => [])
RSpec.should_receive(:reset)
RSpec::Core::Runner.run([], err, out)
end
context "with --drb or -X" do
before(:each) do
@options = RSpec::Core::ConfigurationOptions.new(%w[--drb --drb-port 8181 --color])
RSpec::Core::ConfigurationOptions.stub(:new) { @options }
end
def run_specs
RSpec::Core::Runner.run(%w[ --drb ], err, out)
end
context 'and a DRb server is running' do
it "builds a DRbCommandLine and runs the specs" do
drb_proxy = double(RSpec::Core::DRbCommandLine, :run => true)
drb_proxy.should_receive(:run).with(err, out)
RSpec::Core::DRbCommandLine.should_receive(:new).and_return(drb_proxy)
run_specs
end
end
context 'and a DRb server is not running' do
before(:each) do
RSpec::Core::DRbCommandLine.should_receive(:new).and_raise(DRb::DRbConnError)
end
it "outputs a message" do
RSpec.configuration.stub(:files_to_run) { [] }
err.should_receive(:puts).with(
"No DRb server is running. Running in local process instead ..."
)
run_specs
end
it "builds a CommandLine and runs the specs" do
process_proxy = double(RSpec::Core::CommandLine, :run => 0)
process_proxy.should_receive(:run).with(err, out)
RSpec::Core::CommandLine.should_receive(:new).and_return(process_proxy)
run_specs
end
end
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/drb_options_spec.rb 0000644 0000041 0000041 00000016114 12261207027 022560 0 ustar www-data www-data require "spec_helper"
require 'rspec/core/drb_options'
describe RSpec::Core::DrbOptions, :isolated_directory => true, :isolated_home => true do
include ConfigOptionsHelper
describe "#drb_argv" do
it "preserves extra arguments" do
File.stub(:exist?) { false }
expect(config_options_object(*%w[ a --drb b --color c ]).drb_argv).to match_array %w[ --color a b c ]
end
%w(--color --fail-fast --profile --backtrace --tty).each do |option|
it "includes #{option}" do
expect(config_options_object("#{option}").drb_argv).to include("#{option}")
end
end
it "includes --failure-exit-code" do
expect(config_options_object(*%w[--failure-exit-code 2]).drb_argv).to include("--failure-exit-code", "2")
end
it "includes --options" do
expect(config_options_object(*%w[--options custom.opts]).drb_argv).to include("--options", "custom.opts")
end
it "includes --order" do
expect(config_options_object(*%w[--order random]).drb_argv).to include('--order', 'random')
end
context "with --example" do
it "includes --example" do
expect(config_options_object(*%w[--example foo]).drb_argv).to include("--example", "foo")
end
it "unescapes characters which were escaped upon storing --example originally" do
expect(config_options_object("--example", "foo\\ bar").drb_argv).to include("--example", "foo bar")
end
end
context "with tags" do
it "includes the inclusion tags" do
coo = config_options_object("--tag", "tag")
expect(coo.drb_argv).to eq(["--tag", "tag"])
end
it "includes the inclusion tags with values" do
coo = config_options_object("--tag", "tag:foo")
expect(coo.drb_argv).to eq(["--tag", "tag:foo"])
end
it "leaves inclusion tags intact" do
coo = config_options_object("--tag", "tag")
coo.drb_argv
expect(coo.filter_manager.inclusions).to eq( {:tag=>true} )
end
it "leaves inclusion tags with values intact" do
coo = config_options_object("--tag", "tag:foo")
coo.drb_argv
expect(coo.filter_manager.inclusions).to eq( {:tag=>'foo'} )
end
it "includes the exclusion tags" do
coo = config_options_object("--tag", "~tag")
expect(coo.drb_argv).to eq(["--tag", "~tag"])
end
it "includes the exclusion tags with values" do
coo = config_options_object("--tag", "~tag:foo")
expect(coo.drb_argv).to eq(["--tag", "~tag:foo"])
end
it "leaves exclusion tags intact" do
coo = config_options_object("--tag", "~tag")
coo.drb_argv
expect(coo.filter_manager.exclusions).to include(:tag=>true)
end
it "leaves exclusion tags with values intact" do
coo = config_options_object("--tag", "~tag:foo")
coo.drb_argv
expect(coo.filter_manager.exclusions).to include(:tag=>'foo')
end
end
context "with formatters" do
it "includes the formatters" do
coo = config_options_object("--format", "d")
expect(coo.drb_argv).to eq(["--format", "d"])
end
it "leaves formatters intact" do
coo = config_options_object("--format", "d")
coo.drb_argv
expect(coo.options[:formatters]).to eq([["d"]])
end
it "leaves output intact" do
coo = config_options_object("--format", "p", "--out", "foo.txt", "--format", "d")
coo.drb_argv
expect(coo.options[:formatters]).to eq([["p","foo.txt"],["d"]])
end
end
context "with --out" do
it "combines with formatters" do
coo = config_options_object(*%w[--format h --out report.html])
expect(coo.drb_argv).to eq(%w[--format h --out report.html])
end
end
context "with --line_number" do
it "includes --line_number" do
expect(config_options_object(*%w[--line_number 35]).drb_argv).to eq(%w[--line_number 35])
end
it "includes multiple lines" do
expect(config_options_object(*%w[-l 90 -l 4 -l 55]).drb_argv).to eq(
%w[--line_number 90 --line_number 4 --line_number 55]
)
end
end
context "with -I libs" do
it "includes -I" do
expect(config_options_object(*%w[-I a_dir]).drb_argv).to eq(%w[-I a_dir])
end
it "includes multiple paths" do
expect(config_options_object(*%w[-I dir_1 -I dir_2 -I dir_3]).drb_argv).to eq(
%w[-I dir_1 -I dir_2 -I dir_3]
)
end
end
context "with --require" do
it "includes --require" do
expect(config_options_object(*%w[--require a_path]).drb_argv).to eq(%w[--require a_path])
end
it "includes multiple paths" do
expect(config_options_object(*%w[--require dir/ --require file.rb]).drb_argv).to eq(
%w[--require dir/ --require file.rb]
)
end
end
context "--drb specified in ARGV" do
it "renders all the original arguments except --drb" do
drb_argv = config_options_object(*%w[ --drb --color --format s --example pattern
--line_number 1 --profile --backtrace -I
path/a -I path/b --require path/c --require
path/d]).drb_argv
expect(drb_argv).to eq(%w[ --color --profile --backtrace --example pattern --line_number 1 --format s -I path/a -I path/b --require path/c --require path/d])
end
end
context "--drb specified in the options file" do
it "renders all the original arguments except --drb" do
File.open("./.rspec", "w") {|f| f << "--drb --color"}
drb_argv = config_options_object(*%w[ --tty --format s --example
pattern --line_number 1 --profile
--backtrace ]).drb_argv
expect(drb_argv).to eq(%w[ --color --profile --backtrace --tty
--example pattern --line_number 1 --format s])
end
end
context "--drb specified in ARGV and the options file" do
it "renders all the original arguments except --drb" do
File.open("./.rspec", "w") {|f| f << "--drb --color"}
drb_argv = config_options_object(*%w[ --drb --format s --example
pattern --line_number 1 --profile
--backtrace]).drb_argv
expect(drb_argv).to eq(%w[ --color --profile --backtrace --example pattern --line_number 1 --format s])
end
end
context "--drb specified in ARGV and in as ARGV-specified --options file" do
it "renders all the original arguments except --drb and --options" do
File.open("./.rspec", "w") {|f| f << "--drb --color"}
drb_argv = config_options_object(*%w[ --drb --format s --example
pattern --line_number 1 --profile
--backtrace]).drb_argv
expect(drb_argv).to eq(%w[ --color --profile --backtrace --example pattern --line_number 1 --format s ])
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/pending_example_spec.rb 0000644 0000041 0000041 00000017110 12261207027 023372 0 ustar www-data www-data 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
rspec-core-2.14.7/spec/rspec/core/kernel_extensions_spec.rb 0000644 0000041 0000041 00000000252 12261207027 023771 0 ustar www-data www-data require 'spec_helper'
describe "extensions" do
describe "debugger" do
it "is defined on Kernel" do
expect(Kernel).to respond_to(:debugger)
end
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/ 0000755 0000041 0000041 00000000000 12261207027 021062 5 ustar www-data www-data rspec-core-2.14.7/spec/rspec/core/formatters/base_text_formatter_spec.rb 0000644 0000041 0000041 00000037262 12261207027 026474 0 ustar www-data www-data require 'spec_helper'
require 'rspec/core/formatters/base_text_formatter'
describe RSpec::Core::Formatters::BaseTextFormatter do
let(:output) { StringIO.new }
let(:formatter) { RSpec::Core::Formatters::BaseTextFormatter.new(output) }
describe "#summary_line" do
it "with 0s outputs pluralized (excluding pending)" do
expect(formatter.summary_line(0,0,0)).to eq("0 examples, 0 failures")
end
it "with 1s outputs singular (including pending)" do
expect(formatter.summary_line(1,1,1)).to eq("1 example, 1 failure, 1 pending")
end
it "with 2s outputs pluralized (including pending)" do
expect(formatter.summary_line(2,2,2)).to eq("2 examples, 2 failures, 2 pending")
end
end
describe "#dump_commands_to_rerun_failed_examples" do
it "includes command to re-run each failed example" do
group = RSpec::Core::ExampleGroup.describe("example group") do
it("fails") { fail }
end
line = __LINE__ - 2
group.run(formatter)
formatter.dump_commands_to_rerun_failed_examples
expect(output.string).to include("rspec #{RSpec::Core::Metadata::relative_path("#{__FILE__}:#{line}")} # example group fails")
end
end
describe "#dump_failures" do
let(:group) { RSpec::Core::ExampleGroup.describe("group name") }
before { RSpec.configuration.stub(:color_enabled?) { false } }
def run_all_and_dump_failures
group.run(formatter)
formatter.dump_failures
end
it "preserves formatting" do
group.example("example name") { expect("this").to eq("that") }
run_all_and_dump_failures
expect(output.string).to match(/group name example name/m)
expect(output.string).to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
end
context "with an exception without a message" do
it "does not throw NoMethodError" do
exception_without_message = Exception.new()
exception_without_message.stub(:message) { nil }
group.example("example name") { raise exception_without_message }
expect { run_all_and_dump_failures }.not_to raise_error
end
it "preserves ancestry" do
example = group.example("example name") { raise "something" }
run_all_and_dump_failures
expect(example.example_group.parent_groups.size).to eq 1
end
end
context "with an exception that has an exception instance as its message" do
it "does not raise NoMethodError" do
gonzo_exception = RuntimeError.new
gonzo_exception.stub(:message) { gonzo_exception }
group.example("example name") { raise gonzo_exception }
expect { run_all_and_dump_failures }.not_to raise_error
end
end
context "with an instance of an anonymous exception class" do
it "substitutes '(anonymous error class)' for the missing class name" do
exception = Class.new(StandardError).new
group.example("example name") { raise exception }
run_all_and_dump_failures
expect(output.string).to include('(anonymous error class)')
end
end
context "with an exception class other than RSpec" do
it "does not show the error class" do
group.example("example name") { raise NameError.new('foo') }
run_all_and_dump_failures
expect(output.string).to match(/NameError/m)
end
end
context "with a failed expectation (rspec-expectations)" do
it "does not show the error class" do
group.example("example name") { expect("this").to eq("that") }
run_all_and_dump_failures
expect(output.string).not_to match(/RSpec/m)
end
end
context "with a failed message expectation (rspec-mocks)" do
it "does not show the error class" do
group.example("example name") { "this".should_receive("that") }
run_all_and_dump_failures
expect(output.string).not_to match(/RSpec/m)
end
end
context 'for #share_examples_for' do
it 'outputs the name and location' do
group.share_examples_for 'foo bar' do
it("example name") { expect("this").to eq("that") }
end
line = __LINE__.next
group.it_should_behave_like('foo bar')
run_all_and_dump_failures
expect(output.string).to include(
'Shared Example Group: "foo bar" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
context 'that contains nested example groups' do
it 'outputs the name and location' do
group.share_examples_for 'foo bar' do
describe 'nested group' do
it("example name") { expect("this").to eq("that") }
end
end
line = __LINE__.next
group.it_should_behave_like('foo bar')
run_all_and_dump_failures
expect(output.string).to include(
'Shared Example Group: "foo bar" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
end
end
context 'for #share_as' do
before { allow(RSpec).to receive(:deprecate) }
it 'outputs the name and location' do
group.share_as :FooBar do
it("example name") { expect("this").to eq("that") }
end
line = __LINE__.next
group.send(:include, FooBar)
run_all_and_dump_failures
expect(output.string).to include(
'Shared Example Group: "FooBar" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
context 'that contains nested example groups' do
it 'outputs the name and location' do
group.share_as :NestedFoo do
describe 'nested group' do
describe 'hell' do
it("example name") { expect("this").to eq("that") }
end
end
end
line = __LINE__.next
group.send(:include, NestedFoo)
run_all_and_dump_failures
expect(output.string).to include(
'Shared Example Group: "NestedFoo" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
end
end
end
describe "#dump_pending" do
let(:group) { RSpec::Core::ExampleGroup.describe("group name") }
before { RSpec.configuration.stub(:color_enabled?) { false } }
def run_all_and_dump_pending
group.run(formatter)
formatter.dump_pending
end
context "with show_failures_in_pending_blocks setting enabled" do
before { RSpec.configuration.stub(:show_failures_in_pending_blocks?) { true } }
it "preserves formatting" do
group.example("example name") { pending { expect("this").to eq("that") } }
run_all_and_dump_pending
expect(output.string).to match(/group name example name/m)
expect(output.string).to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
end
context "with an exception without a message" do
it "does not throw NoMethodError" do
exception_without_message = Exception.new()
exception_without_message.stub(:message) { nil }
group.example("example name") { pending { raise exception_without_message } }
expect { run_all_and_dump_pending }.not_to raise_error
end
end
context "with an exception class other than RSpec" do
it "does not show the error class" do
group.example("example name") { pending { raise NameError.new('foo') } }
run_all_and_dump_pending
expect(output.string).to match(/NameError/m)
end
end
context "with a failed expectation (rspec-expectations)" do
it "does not show the error class" do
group.example("example name") { pending { expect("this").to eq("that") } }
run_all_and_dump_pending
expect(output.string).not_to match(/RSpec/m)
end
end
context "with a failed message expectation (rspec-mocks)" do
it "does not show the error class" do
group.example("example name") { pending { "this".should_receive("that") } }
run_all_and_dump_pending
expect(output.string).not_to match(/RSpec/m)
end
end
context 'for #share_examples_for' do
it 'outputs the name and location' do
group.share_examples_for 'foo bar' do
it("example name") { pending { expect("this").to eq("that") } }
end
line = __LINE__.next
group.it_should_behave_like('foo bar')
run_all_and_dump_pending
expect(output.string).to include(
'Shared Example Group: "foo bar" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
context 'that contains nested example groups' do
it 'outputs the name and location' do
group.share_examples_for 'foo bar' do
describe 'nested group' do
it("example name") { pending { expect("this").to eq("that") } }
end
end
line = __LINE__.next
group.it_should_behave_like('foo bar')
run_all_and_dump_pending
expect(output.string).to include(
'Shared Example Group: "foo bar" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
end
end
context 'for #share_as' do
before { allow(RSpec).to receive(:deprecate) }
it 'outputs the name and location' do
group.share_as :FooBar2 do
it("example name") { pending { expect("this").to eq("that") } }
end
line = __LINE__.next
group.send(:include, FooBar2)
run_all_and_dump_pending
expect(output.string).to include(
'Shared Example Group: "FooBar2" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
context 'that contains nested example groups' do
it 'outputs the name and location' do
group.share_as :NestedFoo2 do
describe 'nested group' do
describe 'hell' do
it("example name") { pending { expect("this").to eq("that") } }
end
end
end
line = __LINE__.next
group.send(:include, NestedFoo2)
run_all_and_dump_pending
expect(output.string).to include(
'Shared Example Group: "NestedFoo2" called from ' +
"./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
)
end
end
end
end
context "with show_failures_in_pending_blocks setting disabled" do
before { RSpec.configuration.stub(:show_failures_in_pending_blocks?) { false } }
it "does not output the failure information" do
group.example("example name") { pending { expect("this").to eq("that") } }
run_all_and_dump_pending
expect(output.string).not_to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
end
end
end
describe "#dump_profile_slowest_examples" do
example_line_number = nil
before do
group = RSpec::Core::ExampleGroup.describe("group") do
# Use a sleep so there is some measurable time, to ensure
# the reported percent is 100%, not 0%.
example("example") { sleep 0.001 }
example_line_number = __LINE__ - 1
end
group.run(double('reporter').as_null_object)
formatter.stub(:examples) { group.examples }
RSpec.configuration.stub(:profile_examples) { 10 }
end
it "names the example" do
formatter.dump_profile_slowest_examples
expect(output.string).to match(/group example/m)
end
it "prints the time" do
formatter.dump_profile_slowest_examples
expect(output.string).to match(/0(\.\d+)? seconds/)
end
it "prints the path" do
formatter.dump_profile_slowest_examples
filename = __FILE__.split(File::SEPARATOR).last
expect(output.string).to match(/#{filename}\:#{example_line_number}/)
end
it "prints the percentage taken from the total runtime" do
formatter.dump_profile_slowest_examples
expect(output.string).to match(/, 100.0% of total time\):/)
end
end
describe "#dump_profile_slowest_example_groups" do
let(:group) do
RSpec::Core::ExampleGroup.describe("slow group") do
# Use a sleep so there is some measurable time, to ensure
# the reported percent is 100%, not 0%.
example("example") { sleep 0.01 }
end
end
let(:rpt) { double('reporter').as_null_object }
before do
group.run(rpt)
RSpec.configuration.stub(:profile_examples) { 10 }
end
context "with one example group" do
before { formatter.stub(:examples) { group.examples } }
it "doesn't profile a single example group" do
formatter.dump_profile_slowest_example_groups
expect(output.string).not_to match(/slowest example groups/)
end
end
context "with multiple example groups" do
before do
group2 = RSpec::Core::ExampleGroup.describe("fast group") do
example("example 1") { sleep 0.004 }
example("example 2") { sleep 0.007 }
end
group2.run(rpt)
formatter.stub(:examples) { group.examples + group2.examples }
end
it "prints the slowest example groups" do
formatter.dump_profile_slowest_example_groups
expect(output.string).to match(/slowest example groups/)
end
it "prints the time" do
formatter.dump_profile_slowest_example_groups
expect(output.string).to match(/0(\.\d+)? seconds/)
end
it "ranks the example groups by average time" do
formatter.dump_profile_slowest_example_groups
expect(output.string).to match(/slow group(.*)fast group/m)
end
end
it "depends on parent_groups to get the top level example group" do
ex = ""
group.describe("group 2") do
describe "group 3" do
ex = example("nested example 1")
end
end
expect(ex.example_group.parent_groups.last).to eq(group)
end
end
describe "custom_colors" do
it "uses the custom success color" do
RSpec.configure do |config|
config.color_enabled = true
config.tty = true
config.success_color = :cyan
end
formatter.dump_summary(0,1,0,0)
expect(output.string).to include("\e[36m")
end
end
describe "#colorize" do
it "accepts a VT100 integer code and formats the text with it" do
expect(formatter.colorize('abc', 32)).to eq "\e[32mabc\e[0m"
end
it "accepts a symbol as a color parameter and translates it to the correct integer code, then formats the text with it" do
expect(formatter.colorize('abc', :green)).to eq "\e[32mabc\e[0m"
end
it "accepts a non-default color symbol as a parameter and translates it to the correct integer code, then formats the text with it" do
expect(formatter.colorize('abc', :cyan)).to eq "\e[36mabc\e[0m"
end
end
described_class::VT100_COLORS.each do |name, number|
next if name == :black
describe "##{name}" do
before do
allow(RSpec.configuration).to receive(:color_enabled?) { true }
allow(RSpec).to receive(:deprecate)
end
it "prints the text using the color code for #{name}" do
expect(formatter.send(name, "text")).to eq("\e[#{number}mtext\e[0m")
end
it "prints a deprecation warning" do
expect(RSpec).to receive(:deprecate) {|*args|
expect(args.first).to match(/#{name}/)
}
formatter.send(name, "text")
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html 0000644 0000041 0000041 00000034150 12261207027 026563 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
./spec/rspec/core/resources/formatter_specs.rb:18:in `(root)'
././spec/support/sandboxed_mock_space.rb:33:in `sandboxed'
././spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
././spec/support/sandboxed_mock_space.rb:32:in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
./spec/rspec/core/resources/formatter_specs.rb:33:in `(root)'
././spec/support/sandboxed_mock_space.rb:33:in `sandboxed'
././spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
././spec/support/sandboxed_mock_space.rb:32:in `sandboxed'
31describe "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
(erb):1:in `result'
./spec/rspec/core/resources/formatter_specs.rb:41:in `(root)'
././spec/support/sandboxed_mock_space.rb:33:in `sandboxed'
././spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
././spec/support/sandboxed_mock_space.rb:32:in `sandboxed'
-1
-
fails with a backtrace containing an erb file
n.nnnns
/foo.html.erb:1:in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html 0000644 0000041 0000041 00000052626 12261207027 026470 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a> :in `block (3 levels) in <top (required)>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `block in run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `block (2 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (5 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (4 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (3 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a> :in `block (2 levels) in <top (required)>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `block in run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `block (2 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (5 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (4 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (3 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
31describe "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
(erb):1:in `<main>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=41">./spec/rspec/core/resources/formatter_specs.rb:41</a> :in `block (2 levels) in <top (required)>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `block in run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `block (2 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (5 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (4 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (3 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
-1
-
fails with a backtrace containing an erb file
n.nnnns
<a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/text_mate_formatted-1.9.3-rbx.html 0000644 0000041 0000041 00000072441 12261207027 027256 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a> :in `__script__'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=45">kernel/common/eval19.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/hash19.rb&line=256">kernel/common/hash19.rb:256</a> :in `fetch'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/io.rb&line=217">kernel/common/io.rb:217</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/dir.rb&line=92">kernel/common/dir.rb:92</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=45">kernel/common/eval19.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=45">kernel/common/eval19.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=103">kernel/common/eval19.rb:103</a> :in `instance_exec'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=698">kernel/loader.rb:698</a> :in `run_at_exits'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=718">kernel/loader.rb:718</a> :in `epilogue'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=851">kernel/loader.rb:851</a> :in `main'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a> :in `__script__'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=45">kernel/common/eval19.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/hash19.rb&line=256">kernel/common/hash19.rb:256</a> :in `fetch'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/io.rb&line=217">kernel/common/io.rb:217</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/dir.rb&line=92">kernel/common/dir.rb:92</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=45">kernel/common/eval19.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=45">kernel/common/eval19.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=103">kernel/common/eval19.rb:103</a> :in `instance_exec'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=698">kernel/loader.rb:698</a> :in `run_at_exits'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=718">kernel/loader.rb:718</a> :in `epilogue'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=851">kernel/loader.rb:851</a> :in `main'
31describe "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
(erb):1:in `__script__'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/block_environment.rb&line=75">kernel/common/block_environment.rb:75</a> :in `call_on_instance'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval.rb&line=75">kernel/common/eval.rb:75</a> :in `eval'
<a href="txmt://open?url=file:///Users/jon/.rvm/rubies/rbx-head/lib/19/erb.rb&line=838">/Users/jon/.rvm/rubies/rbx-head/lib/19/erb.rb:838</a> :in `result'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=41">./spec/rspec/core/resources/formatter_specs.rb:41</a> :in `__script__'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=45">kernel/common/eval19.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/hash19.rb&line=256">kernel/common/hash19.rb:256</a> :in `fetch'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/io.rb&line=217">kernel/common/io.rb:217</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/dir.rb&line=92">kernel/common/dir.rb:92</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=45">kernel/common/eval19.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=45">kernel/common/eval19.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval19.rb&line=103">kernel/common/eval19.rb:103</a> :in `instance_exec'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array19.rb&line=18">kernel/bootstrap/array19.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=698">kernel/loader.rb:698</a> :in `run_at_exits'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=718">kernel/loader.rb:718</a> :in `epilogue'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=851">kernel/loader.rb:851</a> :in `main'
-1
-
fails with a backtrace containing an erb file
n.nnnns
<a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/text_mate_formatter_spec.rb 0000644 0000041 0000041 00000006156 12261207027 026506 0 ustar www-data www-data # encoding: utf-8
require 'spec_helper'
require 'rspec/core/formatters/text_mate_formatter'
require 'nokogiri'
module RSpec
module Core
module Formatters
describe TextMateFormatter do
let(:suffix) {
if ::RUBY_PLATFORM == 'java'
"-jruby"
elsif defined?(Rubinius)
"-rbx"
else
""
end
}
let(:root) { File.expand_path("#{File.dirname(__FILE__)}/../../../..") }
let(:expected_file) do
"#{File.dirname(__FILE__)}/text_mate_formatted-#{::RUBY_VERSION}#{suffix}.html"
end
let(:generated_html) do
options = RSpec::Core::ConfigurationOptions.new(
%w[spec/rspec/core/resources/formatter_specs.rb --format textmate --order default]
)
options.parse_options
err, out = StringIO.new, StringIO.new
err.set_encoding("utf-8") if err.respond_to?(:set_encoding)
out.set_encoding("utf-8") if out.respond_to?(:set_encoding)
command_line = RSpec::Core::CommandLine.new(options)
command_line.instance_variable_get("@configuration").backtrace_cleaner.inclusion_patterns = []
command_line.run(err, out)
out.string.gsub(/\d+\.\d+(s| seconds)/, "n.nnnn\\1")
end
let(:expected_html) do
unless File.file?(expected_file)
raise "There is no HTML file with expected content for this platform: #{expected_file}"
end
File.read(expected_file)
end
before do
RSpec.configuration.stub(:load_spec_files) do
RSpec.configuration.files_to_run.map {|f| load File.expand_path(f) }
end
end
# Uncomment this group temporarily in order to overwrite the expected
# with actual. Use with care!!!
describe "file generator", :if => ENV['GENERATE'] do
it "generates a new comparison file" do
Dir.chdir(root) do
File.open(expected_file, 'w') {|io| io.write(generated_html)}
end
end
end
it "produces HTML identical to the one we designed manually" do
Dir.chdir(root) do
actual_doc = Nokogiri::HTML(generated_html)
backtrace_lines = actual_doc.search("div.backtrace a")
actual_doc.search("div.backtrace").remove
expected_doc = Nokogiri::HTML(expected_html)
expected_doc.search("div.backtrace").remove
expect(actual_doc.inner_html).to eq(expected_doc.inner_html)
backtrace_lines.each do |backtrace_line|
expect(backtrace_line['href']).to include("txmt://open?url=")
end
end
end
it "has a backtrace line from the raw erb evaluation" do
Dir.chdir(root) do
actual_doc = Nokogiri::HTML(generated_html)
expect(actual_doc.inner_html).to include('(erb):1')
end
end
it "has a backtrace line from a erb source file we forced to appear" do
expect(generated_html).to include('open?url=file:///foo.html.erb')
end
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html 0000644 0000041 0000041 00000042536 12261207027 026232 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
./spec/rspec/core/resources/formatter_specs.rb:18:in `__script__'
kernel/common/eval19.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:33:in `run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/array19.rb:18:in `map'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `Formatters'
kernel/common/hash19.rb:256:in `fetch'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/io.rb:217:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/dir.rb:92:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `Formatters'
kernel/common/eval19.rb:45:in `instance_eval'
kernel/bootstrap/proc.rb:22:in `call'
kernel/common/eval19.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
kernel/common/eval19.rb:103:in `instance_exec'
kernel/bootstrap/proc.rb:22:in `call'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/proc.rb:22:in `call'
kernel/loader.rb:698:in `run_at_exits'
kernel/loader.rb:718:in `epilogue'
kernel/loader.rb:851:in `main'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
./spec/rspec/core/resources/formatter_specs.rb:33:in `__script__'
kernel/common/eval19.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:33:in `run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/array19.rb:18:in `map'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `Formatters'
kernel/common/hash19.rb:256:in `fetch'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/io.rb:217:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/dir.rb:92:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `Formatters'
kernel/common/eval19.rb:45:in `instance_eval'
kernel/bootstrap/proc.rb:22:in `call'
kernel/common/eval19.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
kernel/common/eval19.rb:103:in `instance_exec'
kernel/bootstrap/proc.rb:22:in `call'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/proc.rb:22:in `call'
kernel/loader.rb:698:in `run_at_exits'
kernel/loader.rb:718:in `epilogue'
kernel/loader.rb:851:in `main'
31describe "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
(erb):1:in `__script__'
kernel/common/block_environment.rb:75:in `call_on_instance'
kernel/common/eval.rb:75:in `eval'
/Users/jon/.rvm/rubies/rbx-head/lib/19/erb.rb:838:in `result'
./spec/rspec/core/resources/formatter_specs.rb:41:in `__script__'
kernel/common/eval19.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:33:in `run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/array19.rb:18:in `map'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `Formatters'
kernel/common/hash19.rb:256:in `fetch'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/io.rb:217:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/dir.rb:92:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `Formatters'
kernel/common/eval19.rb:45:in `instance_eval'
kernel/bootstrap/proc.rb:22:in `call'
kernel/common/eval19.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
kernel/common/eval19.rb:103:in `instance_exec'
kernel/bootstrap/proc.rb:22:in `call'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/array19.rb:18:in `map'
kernel/bootstrap/proc.rb:22:in `call'
kernel/loader.rb:698:in `run_at_exits'
kernel/loader.rb:718:in `epilogue'
kernel/loader.rb:851:in `main'
-1
-
fails with a backtrace containing an erb file
n.nnnns
/foo.html.erb:1:in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/snippet_extractor_spec.rb 0000644 0000041 0000041 00000001656 12261207027 026206 0 ustar www-data www-data require 'spec_helper'
require 'rspec/core/formatters/snippet_extractor'
module RSpec
module Core
module Formatters
describe SnippetExtractor do
it "falls back on a default message when it doesn't understand a line" do
expect(RSpec::Core::Formatters::SnippetExtractor.new.snippet_for("blech")).to eq(["# Couldn't get snippet for blech", 1])
end
it "falls back on a default message when it doesn't find the file" do
expect(RSpec::Core::Formatters::SnippetExtractor.new.lines_around("blech", 8)).to eq("# Couldn't get snippet for blech")
end
it "falls back on a default message when it gets a security error" do
message = nil
safely do
message = RSpec::Core::Formatters::SnippetExtractor.new.lines_around("blech", 8)
end
expect(message).to eq("# Couldn't get snippet for blech")
end
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/deprecation_formatter_spec.rb 0000644 0000041 0000041 00000007010 12261207027 026777 0 ustar www-data www-data require 'spec_helper'
require 'rspec/core/formatters/deprecation_formatter'
require 'tempfile'
module RSpec::Core::Formatters
describe DeprecationFormatter do
let(:deprecation_stream) { StringIO.new }
let(:summary_stream) { StringIO.new }
let(:formatter) { DeprecationFormatter.new deprecation_stream, summary_stream }
def with_start_defined_on_kernel
return yield if ::Kernel.method_defined?(:start)
begin
::Kernel.module_eval { def start(*); raise "boom"; end }
yield
ensure
::Kernel.module_eval { undef start }
end
end
it 'does not blow up when `Kernel` defines `start`' do
with_start_defined_on_kernel do
reporter = ::RSpec::Core::Reporter.new(formatter)
reporter.start(3)
end
end
describe "#deprecation" do
it "includes the method" do
formatter.deprecation(:deprecated => "i_am_deprecated")
deprecation_stream.rewind
expect(deprecation_stream.read).to match(/i_am_deprecated is deprecated/)
end
it "includes the replacement" do
formatter.deprecation(:replacement => "use_me")
deprecation_stream.rewind
expect(deprecation_stream.read).to match(/Use use_me instead/)
end
it "includes the call site if provided" do
formatter.deprecation(:call_site => "somewhere")
deprecation_stream.rewind
expect(deprecation_stream.read).to match(/Called from somewhere/)
end
it "prints a message if provided, ignoring other data" do
formatter.deprecation(:message => "this message", :deprecated => "x", :replacement => "y", :call_site => "z")
deprecation_stream.rewind
expect(deprecation_stream.read).to eq "this message"
end
end
describe "#deprecation_summary" do
it "is printed when deprecations go to a file" do
file = File.open("#{Dir.tmpdir}/deprecation_summary_example_output", "w")
summary_stream = StringIO.new
formatter = DeprecationFormatter.new file, summary_stream
formatter.deprecation(:deprecated => 'i_am_deprecated')
formatter.deprecation_summary
summary_stream.rewind
expect(summary_stream.read).to match(/1 deprecation logged to .*deprecation_summary_example_output/)
end
it "pluralizes for more than one deprecation" do
file = File.open("#{Dir.tmpdir}/deprecation_summary_example_output", "w")
summary_stream = StringIO.new
formatter = DeprecationFormatter.new file, summary_stream
formatter.deprecation(:deprecated => 'i_am_deprecated')
formatter.deprecation(:deprecated => 'i_am_deprecated_also')
formatter.deprecation_summary
summary_stream.rewind
expect(summary_stream.read).to match(/2 deprecations/)
end
it "is not printed when there are no deprecations" do
file = File.open("#{Dir.tmpdir}/deprecation_summary_example_output", "w")
summary_stream = StringIO.new
formatter = DeprecationFormatter.new file, summary_stream
formatter.deprecation_summary
summary_stream.rewind
expect(summary_stream.read).to eq ""
end
it "is not printed when deprecations go to an IO instance" do
summary_stream = StringIO.new
formatter = DeprecationFormatter.new StringIO.new, summary_stream
formatter.deprecation(:deprecated => 'i_am_deprecated')
formatter.deprecation_summary
summary_stream.rewind
expect(summary_stream.read).to eq ""
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/progress_formatter_spec.rb 0000644 0000041 0000041 00000001515 12261207027 026352 0 ustar www-data www-data require 'spec_helper'
require 'rspec/core/formatters/progress_formatter'
describe RSpec::Core::Formatters::ProgressFormatter do
before do
@output = StringIO.new
@formatter = RSpec::Core::Formatters::ProgressFormatter.new(@output)
@formatter.start(2)
@formatter.stub(:color_enabled?).and_return(false)
end
it "produces line break on start dump" do
@formatter.start_dump
expect(@output.string).to eq("\n")
end
it "produces standard summary without pending when pending has a 0 count" do
@formatter.start_dump
@formatter.dump_summary(0.00001, 2, 0, 0)
expect(@output.string).to match(/2 examples, 0 failures/i)
expect(@output.string).not_to match(/0 pending/i)
end
it "pushes nothing on start" do
@formatter.start(4)
expect(@output.string).to eq("")
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html 0000644 0000041 0000041 00000042536 12261207027 026235 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
./spec/rspec/core/resources/formatter_specs.rb:18:in `__script__'
kernel/common/eval18.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:33:in `run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/array18.rb:18:in `map'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `Formatters'
kernel/common/hash18.rb:195:in `fetch'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/io.rb:217:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/dir.rb:92:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `Formatters'
kernel/common/eval18.rb:45:in `instance_eval'
kernel/bootstrap/proc.rb:22:in `call'
kernel/common/eval18.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
kernel/common/eval18.rb:104:in `instance_exec'
kernel/bootstrap/proc.rb:22:in `call'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/proc.rb:22:in `call'
kernel/loader.rb:698:in `run_at_exits'
kernel/loader.rb:718:in `epilogue'
kernel/loader.rb:851:in `main'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
./spec/rspec/core/resources/formatter_specs.rb:33:in `__script__'
kernel/common/eval18.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:33:in `run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/array18.rb:18:in `map'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `Formatters'
kernel/common/hash18.rb:195:in `fetch'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/io.rb:217:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/dir.rb:92:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `Formatters'
kernel/common/eval18.rb:45:in `instance_eval'
kernel/bootstrap/proc.rb:22:in `call'
kernel/common/eval18.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
kernel/common/eval18.rb:104:in `instance_exec'
kernel/bootstrap/proc.rb:22:in `call'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/proc.rb:22:in `call'
kernel/loader.rb:698:in `run_at_exits'
kernel/loader.rb:718:in `epilogue'
kernel/loader.rb:851:in `main'
31describe "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
(erb):1:in `__script__'
kernel/common/block_environment.rb:75:in `call_on_instance'
kernel/common/eval.rb:75:in `eval'
/Users/jon/.rvm/rubies/rbx-head/lib/18/erb.rb:719:in `result'
./spec/rspec/core/resources/formatter_specs.rb:41:in `__script__'
kernel/common/eval18.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:33:in `run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/array18.rb:18:in `map'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `Formatters'
kernel/common/hash18.rb:195:in `fetch'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/io.rb:217:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `Formatters'
kernel/common/dir.rb:92:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `Formatters'
kernel/common/eval18.rb:45:in `instance_eval'
kernel/bootstrap/proc.rb:22:in `call'
kernel/common/eval18.rb:45:in `instance_eval'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
kernel/common/eval18.rb:104:in `instance_exec'
kernel/bootstrap/proc.rb:22:in `call'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/array18.rb:18:in `map'
kernel/bootstrap/proc.rb:22:in `call'
kernel/loader.rb:698:in `run_at_exits'
kernel/loader.rb:718:in `epilogue'
kernel/loader.rb:851:in `main'
-1
-
fails with a backtrace containing an erb file
n.nnnns
/foo.html.erb:1:in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/text_mate_formatted-1.9.3-jruby.html 0000644 0000041 0000041 00000037721 12261207027 027620 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a> :in `(root)'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">././spec/support/sandboxed_mock_space.rb:33</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">././spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">././spec/support/sandboxed_mock_space.rb:32</a> :in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a> :in `(root)'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">././spec/support/sandboxed_mock_space.rb:33</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">././spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">././spec/support/sandboxed_mock_space.rb:32</a> :in `sandboxed'
31describe "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
(erb):1:in `result'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=41">./spec/rspec/core/resources/formatter_specs.rb:41</a> :in `(root)'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">././spec/support/sandboxed_mock_space.rb:33</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">././spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">././spec/support/sandboxed_mock_space.rb:32</a> :in `sandboxed'
-1
-
fails with a backtrace containing an erb file
n.nnnns
<a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/html_formatted-1.9.3.html 0000644 0000041 0000041 00000037753 12261207027 025446 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
./spec/rspec/core/resources/formatter_specs.rb:18:in `block (3 levels) in <top (required)>'
./spec/support/sandboxed_mock_space.rb:33:in `block in run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `block (2 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (5 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (4 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `block (3 levels) in <module:Formatters>'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- 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)>'
./spec/support/sandboxed_mock_space.rb:33:in `block in run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `block (2 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (5 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (4 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `block (3 levels) in <module:Formatters>'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
31describe "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
(erb):1:in `<main>'
./spec/rspec/core/resources/formatter_specs.rb:41:in `block (2 levels) in <top (required)>'
./spec/support/sandboxed_mock_space.rb:33:in `block in run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `block (2 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (5 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (4 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `block (3 levels) in <module:Formatters>'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
-1
-
fails with a backtrace containing an erb file
n.nnnns
/foo.html.erb:1:in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/html_formatter_spec.rb 0000644 0000041 0000041 00000007522 12261207027 025456 0 ustar www-data www-data # encoding: utf-8
require 'spec_helper'
require 'rspec/core/formatters/html_formatter'
require 'nokogiri'
module RSpec
module Core
module Formatters
describe HtmlFormatter, :if => RUBY_VERSION =~ /^(1.8.7|1.9.2|1.9.3|2.0.0)$/ do
let(:suffix) {
if ::RUBY_PLATFORM == 'java'
"-jruby"
elsif defined?(Rubinius)
"-rbx"
else
""
end
}
let(:root) { File.expand_path("#{File.dirname(__FILE__)}/../../../..") }
let(:expected_file) do
"#{File.dirname(__FILE__)}/html_formatted-#{::RUBY_VERSION}#{suffix}.html"
end
let(:generated_html) do
options = RSpec::Core::ConfigurationOptions.new(
%w[spec/rspec/core/resources/formatter_specs.rb --format html --order default]
)
options.parse_options
err, out = StringIO.new, StringIO.new
err.set_encoding("utf-8") if err.respond_to?(:set_encoding)
out.set_encoding("utf-8") if out.respond_to?(:set_encoding)
command_line = RSpec::Core::CommandLine.new(options)
command_line.instance_variable_get("@configuration").backtrace_cleaner.inclusion_patterns = []
command_line.run(err, out)
out.string.gsub(/\d+\.\d+(s| seconds)/, "n.nnnn\\1")
end
let(:expected_html) do
unless File.file?(expected_file)
raise "There is no HTML file with expected content for this platform: #{expected_file}"
end
File.read(expected_file)
end
before do
RSpec.configuration.stub(:load_spec_files) do
RSpec.configuration.files_to_run.map {|f| load File.expand_path(f) }
end
end
# Uncomment this group temporarily in order to overwrite the expected
# with actual. Use with care!!!
describe "file generator", :if => ENV['GENERATE'] do
it "generates a new comparison file" do
Dir.chdir(root) do
File.open(expected_file, 'w') {|io| io.write(generated_html)}
end
end
end
def extract_backtrace_from(doc)
doc.search("div.backtrace").
collect {|e| e.at("pre").inner_html}.
collect {|e| e.split("\n")}.flatten.
select {|e| e =~ /formatter_specs\.rb/}
end
describe 'produced HTML' do
def build_and_verify_formatter_output
Dir.chdir(root) do
actual_doc = Nokogiri::HTML(generated_html)
actual_backtraces = extract_backtrace_from(actual_doc)
actual_doc.css("div.backtrace").remove
expected_doc = Nokogiri::HTML(expected_html)
expected_backtraces = extract_backtrace_from(expected_doc)
expected_doc.search("div.backtrace").remove
expect(actual_doc.inner_html).to eq(expected_doc.inner_html)
expected_backtraces.each_with_index do |expected_line, i|
expected_path, expected_line_number, expected_suffix = expected_line.split(':')
actual_path, actual_line_number, actual_suffix = actual_backtraces[i].split(':')
expect(File.expand_path(actual_path)).to eq(File.expand_path(expected_path))
expect(actual_line_number).to eq(expected_line_number)
expect(actual_suffix).to eq(expected_suffix)
end
end
end
it "produces HTML identical to the one we designed manually" do
build_and_verify_formatter_output
end
context 'with mathn loaded' do
include MathnIntegrationSupport
it "produces HTML identical to the one we designed manually" do
with_mathn_loaded{ build_and_verify_formatter_output }
end
end
end
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html 0000644 0000041 0000041 00000052626 12261207027 026467 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a> :in `block (3 levels) in <top (required)>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `block in run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `block (2 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (5 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (4 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (3 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a> :in `block (2 levels) in <top (required)>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `block in run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `block (2 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (5 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (4 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (3 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
31describe "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
(erb):1:in `<main>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=41">./spec/rspec/core/resources/formatter_specs.rb:41</a> :in `block (2 levels) in <top (required)>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `block in run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `block (2 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (5 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (4 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (3 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
-1
-
fails with a backtrace containing an erb file
n.nnnns
<a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/html_formatted-2.0.0.html 0000644 0000041 0000041 00000040167 12261207027 025424 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
./spec/rspec/core/resources/formatter_specs.rb:18:in `block (3 levels) in <top (required)>'
./spec/support/sandboxed_mock_space.rb:33:in `block in run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `block (2 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (5 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (4 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `block (3 levels) in <module:Formatters>'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- 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)>'
./spec/support/sandboxed_mock_space.rb:33:in `block in run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `block (2 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (5 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (4 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `block (3 levels) in <module:Formatters>'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
31describe "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
(erb):1:in `<main>'
./spec/rspec/core/resources/formatter_specs.rb:41:in `block (2 levels) in <top (required)>'
./spec/support/sandboxed_mock_space.rb:33:in `block in run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `block (2 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (5 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (4 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `block (3 levels) in <module:Formatters>'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
-1
-
fails with a backtrace containing an erb file
n.nnnns
/foo.html.erb:1:in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/documentation_formatter_spec.rb 0000644 0000041 0000041 00000005072 12261207027 027361 0 ustar www-data www-data require 'spec_helper'
require 'rspec/core/formatters/documentation_formatter'
module RSpec::Core::Formatters
describe DocumentationFormatter do
it "numbers the failures" do
examples = [
double("example 1",
:description => "first example",
:execution_result => {:status => 'failed', :exception => Exception.new }
),
double("example 2",
:description => "second example",
:execution_result => {:status => 'failed', :exception => Exception.new }
)
]
output = StringIO.new
RSpec.configuration.stub(:color_enabled?) { false }
formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
examples.each {|e| formatter.example_failed(e) }
expect(output.string).to match(/first example \(FAILED - 1\)/m)
expect(output.string).to match(/second example \(FAILED - 2\)/m)
end
it "represents nested group using hierarchy tree" do
output = StringIO.new
RSpec.configuration.stub(:color_enabled?) { false }
formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
group = RSpec::Core::ExampleGroup.describe("root")
context1 = group.describe("context 1")
context1.example("nested example 1.1"){}
context1.example("nested example 1.2"){}
context11 = context1.describe("context 1.1")
context11.example("nested example 1.1.1"){}
context11.example("nested example 1.1.2"){}
context2 = group.describe("context 2")
context2.example("nested example 2.1"){}
context2.example("nested example 2.2"){}
group.run(RSpec::Core::Reporter.new(formatter))
expect(output.string).to eql("
root
context 1
nested example 1.1
nested example 1.2
context 1.1
nested example 1.1.1
nested example 1.1.2
context 2
nested example 2.1
nested example 2.2
")
end
it "strips whitespace for each row" do
output = StringIO.new
RSpec.configuration.stub(:color_enabled?) { false }
formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
group = RSpec::Core::ExampleGroup.describe(" root ")
context1 = group.describe(" nested ")
context1.example(" example 1 ") {}
context1.example(" example 2 ", :pending => true){}
context1.example(" example 3 ") { fail }
group.run(RSpec::Core::Reporter.new(formatter))
expect(output.string).to eql("
root
nested
example 1
example 2 (PENDING: No reason given)
example 3 (FAILED - 1)
")
end
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/html_formatted-1.9.2.html 0000644 0000041 0000041 00000037753 12261207027 025445 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
./spec/rspec/core/resources/formatter_specs.rb:18:in `block (3 levels) in <top (required)>'
./spec/support/sandboxed_mock_space.rb:33:in `block in run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `block (2 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (5 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (4 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `block (3 levels) in <module:Formatters>'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- 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)>'
./spec/support/sandboxed_mock_space.rb:33:in `block in run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `block (2 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (5 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (4 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `block (3 levels) in <module:Formatters>'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
31describe "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
(erb):1:in `<main>'
./spec/rspec/core/resources/formatter_specs.rb:41:in `block (2 levels) in <top (required)>'
./spec/support/sandboxed_mock_space.rb:33:in `block in run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `block (2 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (5 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `block (4 levels) in <module:Formatters>'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `block (3 levels) in <module:Formatters>'
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
-1
-
fails with a backtrace containing an erb file
n.nnnns
/foo.html.erb:1:in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/json_formatter_spec.rb 0000644 0000041 0000041 00000007244 12261207027 025464 0 ustar www-data www-data require 'spec_helper'
require 'rspec/core/formatters/json_formatter'
require 'json'
require 'rspec/core/reporter'
# todo, someday:
# it "lists the groups (describe and context) separately"
# it "includes full 'execution_result'"
# it "relativizes backtrace paths"
# it "includes profile information (implements dump_profile)"
# it "shows the pending message if one was given"
# it "shows the seed if run was randomized"
# it "lists pending specs that were fixed"
describe RSpec::Core::Formatters::JsonFormatter do
let(:output) { StringIO.new }
let(:formatter) { RSpec::Core::Formatters::JsonFormatter.new(output) }
let(:reporter) { RSpec::Core::Reporter.new(formatter) }
it "outputs json (brittle high level functional test)" do
group = RSpec::Core::ExampleGroup.describe("one apiece") do
it("succeeds") { expect(1).to eq 1 }
it("fails") { fail "eek" }
it("pends") { pending "world peace" }
end
succeeding_line = __LINE__ - 4
failing_line = __LINE__ - 4
pending_line = __LINE__ - 4
now = Time.now
Time.stub(:now).and_return(now)
reporter.report(2) do |r|
group.run(r)
end
# grab the actual backtrace -- kind of a cheat
failing_backtrace = formatter.output_hash[:examples][1][:exception][:backtrace]
this_file = relative_path(__FILE__)
expected = {
:examples => [
{
:description => "succeeds",
:full_description => "one apiece succeeds",
:status => "passed",
:file_path => this_file,
:line_number => succeeding_line,
},
{
:description => "fails",
:full_description => "one apiece fails",
:status => "failed",
:file_path => this_file,
:line_number => failing_line,
:exception => {:class => "RuntimeError", :message => "eek", :backtrace => failing_backtrace}
},
{
:description => "pends",
:full_description => "one apiece pends",
:status => "pending",
:file_path => this_file,
:line_number => pending_line,
},
],
:summary => {
:duration => formatter.output_hash[:summary][:duration],
:example_count => 3,
:failure_count => 1,
:pending_count => 1,
},
:summary_line => "3 examples, 1 failure, 1 pending"
}
expect(formatter.output_hash).to eq expected
expect(output.string).to eq expected.to_json
end
describe "#stop" do
it "adds all examples to the output hash" do
formatter.stop
expect(formatter.output_hash[:examples]).not_to be_nil
end
end
describe "#close" do
it "outputs the results as a JSON string" do
expect(output.string).to eq ""
formatter.close
expect(output.string).to eq({}.to_json)
end
end
describe "#message" do
it "adds a message to the messages list" do
formatter.message("good job")
expect(formatter.output_hash[:messages]).to eq ["good job"]
end
end
describe "#dump_summary" do
it "adds summary info to the output hash" do
duration, example_count, failure_count, pending_count = 1.0, 2, 1, 1
formatter.dump_summary(duration, example_count, failure_count, pending_count)
summary = formatter.output_hash[:summary]
%w(duration example_count failure_count pending_count).each do |key|
expect(summary[key.to_sym]).to eq eval(key)
end
summary_line = formatter.output_hash[:summary_line]
expect(summary_line).to eq "2 examples, 1 failure, 1 pending"
end
it "ignores --profile" do
allow(RSpec.configuration).to receive(:profile_examples).and_return(true)
formatter.dump_summary(1.0, 2, 1, 1)
end
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html 0000644 0000041 0000041 00000044306 12261207027 026467 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a>
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `generated_html'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a>
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a>
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a>
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a>
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `generated_html'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a>
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a>
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a>
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
31describe "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
-
fails with a backtrace containing an erb file
n.nnnns
<a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/helpers_spec.rb 0000644 0000041 0000041 00000005547 12261207027 024076 0 ustar www-data www-data require 'spec_helper'
require 'rspec/core/formatters/helpers'
describe RSpec::Core::Formatters::Helpers do
let(:helper) { Object.new.extend(RSpec::Core::Formatters::Helpers) }
describe "format duration" do
context '< 1' do
it "returns '0.xxxxx seconds' formatted string" do
expect(helper.format_duration(0.123456)).to eq("0.12346 seconds")
end
end
context '> 1 and < 60' do
it "returns 'xx.xx seconds' formatted string" do
expect(helper.format_duration(45.51)).to eq("45.51 seconds")
end
end
context '> 60 and < 120' do
it "returns 'x minute xx.xx seconds' formatted string" do
expect(helper.format_duration(70.14)).to eq("1 minute 10.14 seconds")
end
end
context '> 120 and < 300' do
it "returns 'x minutes xx.x seconds' formatted string" do
expect(helper.format_duration(135.14)).to eq("2 minutes 15.1 seconds")
end
end
context '> 300' do
it "returns 'x minutes xx seconds' formatted string" do
expect(helper.format_duration(335.14)).to eq("5 minutes 35 seconds")
end
end
context '= 61' do
it "returns 'x minute x second' formatted string" do
expect(helper.format_duration(61)).to eq("1 minute 1 second")
end
end
context '= 1' do
it "returns 'x second' formatted string" do
expect(helper.format_duration(1)).to eq("1 second")
end
end
context 'with mathn loaded' do
include MathnIntegrationSupport
it "returns 'x minutes xx.x seconds' formatted string" do
with_mathn_loaded do
expect(helper.format_duration(133.7)).to eq("2 minutes 13.7 seconds")
end
end
end
end
describe "format seconds" do
it "uses passed in precision if specified unless result is 0" do
expect(helper.format_seconds(0.01234, 2)).to eq("0.01")
end
context "sub second times" do
it "returns 5 digits of precision" do
expect(helper.format_seconds(0.000006)).to eq("0.00001")
end
it "strips off trailing zeroes beyond sub-second precision" do
expect(helper.format_seconds(0.020000)).to eq("0.02")
end
context "0" do
it "strips off trailing zeroes" do
expect(helper.format_seconds(0.00000000001)).to eq("0")
end
end
context "> 1" do
it "strips off trailing zeroes" do
expect(helper.format_seconds(1.00000000001)).to eq("1")
end
end
end
context "second and greater times" do
it "returns 2 digits of precision" do
expect(helper.format_seconds(50.330340)).to eq("50.33")
end
it "returns human friendly elasped time" do
expect(helper.format_seconds(50.1)).to eq("50.1")
expect(helper.format_seconds(5)).to eq("5")
expect(helper.format_seconds(5.0)).to eq("5")
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/html_formatted-1.8.7.html 0000644 0000041 0000041 00000035211 12261207027 025434 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
./spec/rspec/core/resources/formatter_specs.rb:18
./spec/support/sandboxed_mock_space.rb:33:in `run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `generated_html'
./spec/rspec/core/formatters/html_formatter_spec.rb:59
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
./spec/rspec/core/resources/formatter_specs.rb:33
./spec/support/sandboxed_mock_space.rb:33:in `run'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `run'
./spec/rspec/core/formatters/html_formatter_spec.rb:37:in `generated_html'
./spec/rspec/core/formatters/html_formatter_spec.rb:59
./spec/rspec/core/formatters/html_formatter_spec.rb:59:in `open'
./spec/rspec/core/formatters/html_formatter_spec.rb:59
./spec/rspec/core/formatters/html_formatter_spec.rb:58:in `chdir'
./spec/rspec/core/formatters/html_formatter_spec.rb:58
./spec/support/sandboxed_mock_space.rb:38:in `sandboxed'
31describe "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
-
fails with a backtrace containing an erb file
n.nnnns
/foo.html.erb:1:in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html 0000644 0000041 0000041 00000034126 12261207027 026571 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
./spec/rspec/core/resources/formatter_specs.rb:18:in `(root)'
./spec/support/sandboxed_mock_space.rb:33:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
./spec/rspec/core/resources/formatter_specs.rb:33:in `(root)'
./spec/support/sandboxed_mock_space.rb:33:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `sandboxed'
31describe "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
(erb):1:in `result'
./spec/rspec/core/resources/formatter_specs.rb:41:in `(root)'
./spec/support/sandboxed_mock_space.rb:33:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:72:in `sandboxed'
./spec/support/sandboxed_mock_space.rb:32:in `sandboxed'
-1
-
fails with a backtrace containing an erb file
n.nnnns
/foo.html.erb:1:in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/text_mate_formatted-1.8.7-rbx.html 0000644 0000041 0000041 00000072441 12261207027 027261 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a> :in `__script__'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=45">kernel/common/eval18.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/hash18.rb&line=195">kernel/common/hash18.rb:195</a> :in `fetch'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/io.rb&line=217">kernel/common/io.rb:217</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/dir.rb&line=92">kernel/common/dir.rb:92</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=45">kernel/common/eval18.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=45">kernel/common/eval18.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=104">kernel/common/eval18.rb:104</a> :in `instance_exec'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=698">kernel/loader.rb:698</a> :in `run_at_exits'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=718">kernel/loader.rb:718</a> :in `epilogue'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=851">kernel/loader.rb:851</a> :in `main'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a> :in `__script__'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=45">kernel/common/eval18.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/hash18.rb&line=195">kernel/common/hash18.rb:195</a> :in `fetch'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/io.rb&line=217">kernel/common/io.rb:217</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/dir.rb&line=92">kernel/common/dir.rb:92</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=45">kernel/common/eval18.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=45">kernel/common/eval18.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=104">kernel/common/eval18.rb:104</a> :in `instance_exec'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=698">kernel/loader.rb:698</a> :in `run_at_exits'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=718">kernel/loader.rb:718</a> :in `epilogue'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=851">kernel/loader.rb:851</a> :in `main'
31describe "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
(erb):1:in `__script__'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/block_environment.rb&line=75">kernel/common/block_environment.rb:75</a> :in `call_on_instance'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval.rb&line=75">kernel/common/eval.rb:75</a> :in `eval'
<a href="txmt://open?url=file:///Users/jon/.rvm/rubies/rbx-head/lib/18/erb.rb&line=719">/Users/jon/.rvm/rubies/rbx-head/lib/18/erb.rb:719</a> :in `result'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=41">./spec/rspec/core/resources/formatter_specs.rb:41</a> :in `__script__'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=45">kernel/common/eval18.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/hash18.rb&line=195">kernel/common/hash18.rb:195</a> :in `fetch'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/io.rb&line=217">kernel/common/io.rb:217</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/dir.rb&line=92">kernel/common/dir.rb:92</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `Formatters'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=45">kernel/common/eval18.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=45">kernel/common/eval18.rb:45</a> :in `instance_eval'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/common/eval18.rb&line=104">kernel/common/eval18.rb:104</a> :in `instance_exec'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/array18.rb&line=18">kernel/bootstrap/array18.rb:18</a> :in `map'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/bootstrap/proc.rb&line=22">kernel/bootstrap/proc.rb:22</a> :in `call'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=698">kernel/loader.rb:698</a> :in `run_at_exits'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=718">kernel/loader.rb:718</a> :in `epilogue'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/kernel/loader.rb&line=851">kernel/loader.rb:851</a> :in `main'
-1
-
fails with a backtrace containing an erb file
n.nnnns
<a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html 0000644 0000041 0000041 00000034212 12261207027 027613 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a> :in `(root)'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a> :in `(root)'
31describe "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
(erb):1:in `result'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=41">./spec/rspec/core/resources/formatter_specs.rb:41</a> :in `(root)'
-1
-
fails with a backtrace containing an erb file
n.nnnns
<a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/formatters/base_formatter_spec.rb 0000644 0000041 0000041 00000007527 12261207027 025431 0 ustar www-data www-data require 'spec_helper'
require 'rspec/core/formatters/base_formatter'
describe RSpec::Core::Formatters::BaseFormatter do
let(:output) { StringIO.new }
let(:formatter) { RSpec::Core::Formatters::BaseFormatter.new(output) }
describe "backtrace_line" do
it "trims current working directory" do
expect(formatter.__send__(:backtrace_line, File.expand_path(__FILE__))).to eq("./spec/rspec/core/formatters/base_formatter_spec.rb")
end
it "leaves the original line intact" do
original_line = File.expand_path(__FILE__)
formatter.__send__(:backtrace_line, original_line)
expect(original_line).to eq(File.expand_path(__FILE__))
end
it "deals gracefully with a security error" do
safely do
formatter.__send__(:backtrace_line, __FILE__)
# on some rubies, this doesn't raise a SecurityError; this test just
# assures that if it *does* raise an error, the error is caught inside
end
end
end
describe "read_failed_line" do
it "deals gracefully with a heterogeneous language stack trace" do
exception = double(:Exception, :backtrace => [
"at Object.prototypeMethod (foo:331:18)",
"at Array.forEach (native)",
"at a_named_javascript_function (/some/javascript/file.js:39:5)",
"/some/line/of/ruby.rb:14"
])
example = double(:Example, :file_path => __FILE__)
expect {
formatter.send(:read_failed_line, exception, example)
}.not_to raise_error
end
it "deals gracefully with a security error" do
exception = double(:Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"])
example = double(:Example, :file_path => __FILE__)
safely do
expect {
formatter.send(:read_failed_line, exception, example)
}.not_to raise_error
end
end
context "when ruby reports a bogus line number in the stack trace" do
it "reports the filename and that it was unable to find the matching line" do
exception = double(:Exception, :backtrace => [ "#{__FILE__}:10000000" ])
example = double(:Example, :file_path => __FILE__)
msg = formatter.send(:read_failed_line, exception, example)
expect(msg).to include("Unable to find matching line")
end
end
context "when String alias to_int to_i" do
before do
String.class_eval do
alias :to_int :to_i
end
end
after do
String.class_eval do
undef to_int
end
end
it "doesn't hang when file exists" do
pending("This issue still exists on JRuby, but should be resolved shortly: https://github.com/rspec/rspec-core/issues/295", :if => RUBY_PLATFORM == 'java')
exception = double(:Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"])
example = double(:Example, :file_path => __FILE__)
expect(formatter.send(:read_failed_line, exception, example)).to eql(
%Q{ exception = double(:Exception, :backtrace => [ "\#{__FILE__}:\#{__LINE__}"])\n})
end
end
end
describe "#format_backtrace" do
let(:rspec_expectations_dir) { "/path/to/rspec-expectations/lib" }
let(:rspec_core_dir) { "/path/to/rspec-core/lib" }
let(:backtrace) do
[
"#{rspec_expectations_dir}/rspec/matchers/operator_matcher.rb:51:in `eval_match'",
"#{rspec_expectations_dir}/rspec/matchers/operator_matcher.rb:29:in `=='",
"./my_spec.rb:5",
"#{rspec_core_dir}/rspec/core/example.rb:52:in `run'",
"#{rspec_core_dir}/rspec/core/runner.rb:37:in `run'",
RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE,
"./my_spec.rb:3"
]
end
it "removes lines from rspec and lines that come before the invocation of the at_exit autorun hook" do
expect(formatter.format_backtrace(backtrace, double.as_null_object)).to eq(["./my_spec.rb:5"])
end
end
end
rspec-core-2.14.7/spec/rspec/core/formatters/text_mate_formatted-2.0.0.html 0000644 0000041 0000041 00000053256 12261207027 026455 0 ustar www-data www-data
RSpec results
- 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)
- with content that would pass
-
fails
n.nnnns
RSpec::Core::Pending::PendingExampleFixedError
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a> :in `block (3 levels) in <top (required)>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `block in run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `block (2 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (5 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (4 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (3 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
16 context "with content that would pass" do
17 it "fails" do
18 pending do
19 expect(1).to eq(1)
20 end
- passing spec
- passesn.nnnns
- failing spec
-
fails
n.nnnns
expected: 2
got: 1
(compared using ==)
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a> :in `block (2 levels) in <top (required)>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `block in run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `block (2 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (5 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (4 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (3 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
31describe "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
(erb):1:in `<main>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=41">./spec/rspec/core/resources/formatter_specs.rb:41</a> :in `block (2 levels) in <top (required)>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=33">./spec/support/sandboxed_mock_space.rb:33</a> :in `block in run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=72">./spec/support/sandboxed_mock_space.rb:72</a> :in `sandboxed'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=32">./spec/support/sandboxed_mock_space.rb:32</a> :in `run'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=37">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:37</a> :in `block (2 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (5 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `open'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=59">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:59</a> :in `block (4 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `chdir'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (3 levels) in <module:Formatters>'
<a href="txmt://open?url=file:///Users/jon/Code/Scratch/rspec-core/spec/support/sandboxed_mock_space.rb&line=38">./spec/support/sandboxed_mock_space.rb:38</a> :in `sandboxed'
-1
-
fails with a backtrace containing an erb file
n.nnnns
<a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `<main>': foo (RuntimeError)
-1
rspec-core-2.14.7/spec/rspec/core/deprecations_spec.rb 0000644 0000041 0000041 00000003514 12261207027 022716 0 ustar www-data www-data require "spec_helper"
describe "deprecated methods" do
describe "Spec" do
it "is deprecated" do
RSpec.should_receive(:deprecate)
Spec
end
it "returns RSpec" do
RSpec.stub(:deprecate)
expect(Spec).to eq(RSpec)
end
it "doesn't include backward compatibility in const_missing backtrace" do
RSpec.stub(:deprecate)
exception = nil
begin
ConstantThatDoesNotExist
rescue Exception => exception
end
expect(exception.backtrace.find { |l| l =~ /lib\/rspec\/core\/backward_compatibility/ }).to be_nil
end
end
describe RSpec::Core::ExampleGroup do
describe 'running_example' do
it 'is deprecated' do
RSpec.should_receive(:deprecate).at_least(:once)
self.running_example
end
it "delegates to example" do
RSpec.stub(:deprecate)
expect(running_example).to eq(example)
end
end
end
describe RSpec::Core::SharedExampleGroup do
describe 'share_as' do
it 'is deprecated' do
RSpec.should_receive(:deprecate).at_least(:once)
RSpec::Core::SharedExampleGroup.share_as(:DeprecatedSharedConst) {}
end
end
end
describe "Spec::Runner.configure" do
it "is deprecated" do
RSpec.should_receive(:deprecate).at_least(:once)
Spec::Runner.configure
end
end
describe "Spec::Rake::SpecTask" do
it "is deprecated" do
RSpec.should_receive(:deprecate).at_least(:once)
Spec::Rake::SpecTask
end
it "doesn't include backward compatibility in const_missing backtrace" do
RSpec.stub(:deprecate)
exception = nil
begin
Spec::Rake::ConstantThatDoesNotExist
rescue Exception => exception
end
expect(exception.backtrace.find { |l| l =~ /lib\/rspec\/core\/backward_compatibility/ }).to be_nil
end
end
end
rspec-core-2.14.7/spec/rspec/core/rake_task_spec.rb 0000644 0000041 0000041 00000012531 12261207027 022201 0 ustar www-data www-data require "spec_helper"
require "rspec/core/rake_task"
require 'tempfile'
module RSpec::Core
describe RakeTask do
let(:task) { RakeTask.new }
def ruby
FileUtils::RUBY
end
def with_rcov
task.rcov = true
yield
end
def spec_command
task.__send__(:spec_command)
end
context "with a name passed to the constructor" do
let(:task) { RakeTask.new(:task_name) }
it "correctly sets the name" do
expect(task.name).to eq :task_name
end
end
context "with args passed to the rake task" do
it "correctly passes along task arguments" do
task = RakeTask.new(:rake_task_args, :files) do |t, args|
expect(args[:files]).to eq "first_spec.rb"
end
task.should_receive(:run_task) { true }
expect(Rake.application.invoke_task("rake_task_args[first_spec.rb]")).to be_true
end
end
context "default" do
it "renders rspec" do
expect(spec_command).to match(/^#{ruby} -S rspec/)
end
end
context "with rcov" do
it "renders rcov" do
with_rcov do
expect(spec_command).to match(/^#{ruby} -S rcov/)
end
end
end
context "with ruby options" do
it "renders them before -S" do
task.ruby_opts = "-w"
expect(spec_command).to match(/^#{ruby} -w -S rspec/)
end
end
context "with rcov_opts" do
context "with rcov=false (default)" do
it "does not add the rcov options to the command" do
task.rcov_opts = '--exclude "mocks"'
expect(spec_command).not_to match(/--exclude "mocks"/)
end
end
context "with rcov=true" do
it "renders them after rcov" do
task.rcov = true
task.rcov_opts = '--exclude "mocks"'
expect(spec_command).to match(/rcov.*--exclude "mocks"/)
end
it "ensures that -Ispec:lib is in the resulting command" do
task.rcov = true
task.rcov_opts = '--exclude "mocks"'
expect(spec_command).to match(/rcov.*-Ispec:lib/)
end
end
end
context "with rspec_opts" do
context "with rcov=true" do
it "adds the rspec_opts after the rcov_opts and files" do
task.stub(:files_to_run) { "this.rb that.rb" }
task.rcov = true
task.rspec_opts = "-Ifoo"
expect(spec_command).to match(/this.rb that.rb -- -Ifoo/)
end
end
context "with rcov=false (default)" do
it "adds the rspec_opts" do
task.rspec_opts = "-Ifoo"
expect(spec_command).to match(/rspec.*-Ifoo/)
end
end
end
def specify_consistent_ordering_of_files_to_run(pattern, task)
orderings = [
%w[ a/1.rb a/2.rb a/3.rb ],
%w[ a/2.rb a/1.rb a/3.rb ],
%w[ a/3.rb a/2.rb a/1.rb ]
].map do |files|
FileList.should_receive(:[]).with(pattern) { files }
task.__send__(:files_to_run)
end
expect(orderings.uniq.size).to eq(1)
end
context "with SPEC env var set" do
it "sets files to run" do
with_env_vars 'SPEC' => 'path/to/file' do
expect(task.__send__(:files_to_run)).to eq(["path/to/file"])
end
end
it "sets the files to run in a consistent order, regardless of the underlying FileList ordering" do
with_env_vars 'SPEC' => 'a/*.rb' do
specify_consistent_ordering_of_files_to_run('a/*.rb', task)
end
end
end
it "sets the files to run in a consistent order, regardless of the underlying FileList ordering" do
task = RakeTask.new(:consistent_file_order) do |t|
t.pattern = 'a/*.rb'
end
# since the config block is deferred til task invocation, must fake
# calling the task so the expected pattern is picked up
task.should_receive(:run_task) { true }
expect(Rake.application.invoke_task(task.name)).to be_true
specify_consistent_ordering_of_files_to_run('a/*.rb', task)
end
context "with paths with quotes or spaces" do
it "escapes the quotes and spaces" do
task.pattern = File.join(Dir.tmpdir, "*spec.rb")
["first_spec.rb", "second_\"spec.rb", "third_\'spec.rb", "fourth spec.rb"].each do |file_name|
FileUtils.touch(File.join(Dir.tmpdir, file_name))
end
expect(task.__send__(:files_to_run).sort).to eq([
File.join(Dir.tmpdir, "first_spec.rb"),
File.join(Dir.tmpdir, "fourth\\ spec.rb"),
File.join(Dir.tmpdir, "second_\\\"spec.rb"),
File.join(Dir.tmpdir, "third_\\\'spec.rb")
])
end
end
context "with paths including symlinked directories" do
it "finds the files" do
project_dir = File.join(Dir.tmpdir, "project")
FileUtils.rm_rf project_dir
foos_dir = File.join(project_dir, "spec/foos")
FileUtils.mkdir_p foos_dir
FileUtils.touch(File.join(foos_dir, "foo_spec.rb"))
bars_dir = File.join(Dir.tmpdir, "shared/spec/bars")
FileUtils.mkdir_p bars_dir
FileUtils.touch(File.join(bars_dir, "bar_spec.rb"))
FileUtils.ln_s bars_dir, File.join(project_dir, "spec/bars")
FileUtils.cd(project_dir) do
expect(RakeTask.new.__send__(:files_to_run).sort).to eq([
"./spec/bars/bar_spec.rb",
"./spec/foos/foo_spec.rb"
])
end
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/option_parser_spec.rb 0000644 0000041 0000041 00000016521 12261207027 023124 0 ustar www-data www-data require "spec_helper"
module RSpec::Core
describe OptionParser do
let(:output_file){ mock File }
before do
RSpec.stub(:deprecate)
File.stub(:open).with("foo.txt",'w') { (output_file) }
end
it "does not parse empty args" do
parser = Parser.new
OptionParser.should_not_receive(:new)
parser.parse!([])
end
it "proposes you to use --help and returns an error on incorrect argument" do
parser = Parser.new
option = "--my_wrong_arg"
parser.should_receive(:abort) do |msg|
expect(msg).to include('use --help', option)
end
parser.parse!([option])
end
describe "--formatter" do
it "is deprecated" do
RSpec.should_receive(:deprecate)
Parser.parse!(%w[--formatter doc])
end
it "gets converted to --format" do
options = Parser.parse!(%w[--formatter doc])
expect(options[:formatters].first).to eq(["doc"])
end
end
describe "--default_path" do
it "gets converted to --default-path" do
options = Parser.parse!(%w[--default_path foo])
expect(options[:default_path]).to eq "foo"
end
end
describe "--line_number" do
it "gets converted to --line-number" do
options = Parser.parse!(%w[--line_number 3])
expect(options[:line_numbers]).to eq ["3"]
end
end
describe "--default-path" do
it "sets the default path where RSpec looks for examples" do
options = Parser.parse!(%w[--default-path foo])
expect(options[:default_path]).to eq "foo"
end
end
%w[--line-number -l].each do |option|
describe option do
it "sets the line number of an example to run" do
options = Parser.parse!([option, "3"])
expect(options[:line_numbers]).to eq ["3"]
end
end
end
%w[--format -f].each do |option|
describe option do
it "defines the formatter" do
options = Parser.parse!([option, 'doc'])
expect(options[:formatters].first).to eq(["doc"])
end
end
end
%w[--out -o].each do |option|
describe option do
let(:options) { Parser.parse!([option, 'out.txt']) }
it "sets the output stream for the formatter" do
expect(options[:formatters].last).to eq(['progress', 'out.txt'])
end
context "with multiple formatters" do
context "after last formatter" do
it "sets the output stream for the last formatter" do
options = Parser.parse!(['-f', 'progress', '-f', 'doc', option, 'out.txt'])
expect(options[:formatters][0]).to eq(['progress'])
expect(options[:formatters][1]).to eq(['doc', 'out.txt'])
end
end
context "after first formatter" do
it "sets the output stream for the first formatter" do
options = Parser.parse!(['-f', 'progress', option, 'out.txt', '-f', 'doc'])
expect(options[:formatters][0]).to eq(['progress', 'out.txt'])
expect(options[:formatters][1]).to eq(['doc'])
end
end
end
end
end
%w[--example -e].each do |option|
describe option do
it "escapes the arg" do
options = Parser.parse!([option, "this (and that)"])
expect(options[:full_description].length).to eq(1)
expect("this (and that)").to match(options[:full_description].first)
end
end
end
%w[--pattern -P].each do |option|
describe option do
it "sets the filename pattern" do
options = Parser.parse!([option, 'spec/**/*.spec'])
expect(options[:pattern]).to eq('spec/**/*.spec')
end
end
end
%w[--tag -t].each do |option|
describe option do
context "without ~" do
it "treats no value as true" do
options = Parser.parse!([option, 'foo'])
expect(options[:inclusion_filter]).to eq(:foo => true)
end
it "treats 'true' as true" do
options = Parser.parse!([option, 'foo:true'])
expect(options[:inclusion_filter]).to eq(:foo => true)
end
it "treats 'nil' as nil" do
options = Parser.parse!([option, 'foo:nil'])
expect(options[:inclusion_filter]).to eq(:foo => nil)
end
it "treats 'false' as false" do
options = Parser.parse!([option, 'foo:false'])
expect(options[:inclusion_filter]).to eq(:foo => false)
end
it "merges muliple invocations" do
options = Parser.parse!([option, 'foo:false', option, 'bar:true', option, 'foo:true'])
expect(options[:inclusion_filter]).to eq(:foo => true, :bar => true)
end
it "treats 'any_string' as 'any_string'" do
options = Parser.parse!([option, 'foo:any_string'])
expect(options[:inclusion_filter]).to eq(:foo => 'any_string')
end
end
context "with ~" do
it "treats no value as true" do
options = Parser.parse!([option, '~foo'])
expect(options[:exclusion_filter]).to eq(:foo => true)
end
it "treats 'true' as true" do
options = Parser.parse!([option, '~foo:true'])
expect(options[:exclusion_filter]).to eq(:foo => true)
end
it "treats 'nil' as nil" do
options = Parser.parse!([option, '~foo:nil'])
expect(options[:exclusion_filter]).to eq(:foo => nil)
end
it "treats 'false' as false" do
options = Parser.parse!([option, '~foo:false'])
expect(options[:exclusion_filter]).to eq(:foo => false)
end
end
end
end
describe "--order" do
it "is nil by default" do
expect(Parser.parse!([])[:order]).to be_nil
end
%w[rand random].each do |option|
context "with #{option}" do
it "defines the order as random" do
options = Parser.parse!(['--order', option])
expect(options[:order]).to eq(option)
end
end
end
end
describe "--seed" do
it "sets the order to rand:SEED" do
options = Parser.parse!(%w[--seed 123])
expect(options[:order]).to eq("rand:123")
end
end
describe '--profile' do
it 'sets profile_examples to true by default' do
options = Parser.parse!(%w[--profile])
expect(options[:profile_examples]).to eq true
end
it 'sets profile_examples to supplied int' do
options = Parser.parse!(%w[--profile 10])
expect(options[:profile_examples]).to eq 10
end
it 'sets profile_examples to true when accidentally combined with path' do
allow(Kernel).to receive(:warn)
options = Parser.parse!(%w[--profile some/path])
expect(options[:profile_examples]).to eq true
end
it 'warns when accidentally combined with path' do
expect(Kernel).to receive(:warn) do |msg|
expect(msg).to match "Non integer specified as profile count"
end
options = Parser.parse!(%w[--profile some/path])
expect(options[:profile_examples]).to eq true
end
end
describe '--warning' do
it 'enables warnings' do
options = Parser.parse!(%w[--warnings])
expect(options[:warnings]).to eq true
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/configuration_spec.rb 0000644 0000041 0000041 00000146317 12261207027 023116 0 ustar www-data www-data require 'spec_helper'
require 'tmpdir'
module RSpec::Core
describe Configuration do
let(:config) { Configuration.new }
describe "RSpec.configuration with a block" do
before { RSpec.stub(:warn_deprecation) }
it "is deprecated" do
RSpec.should_receive(:warn_deprecation)
RSpec.configuration {}
end
end
describe '#deprecation_stream' do
it 'defaults to standard error' do
expect(config.deprecation_stream).to eq $stderr
end
it 'is configurable' do
io = double 'deprecation io'
config.deprecation_stream = io
expect(config.deprecation_stream).to eq io
end
end
describe "#setup_load_path_and_require" do
include_context "isolate load path mutation"
def absolute_path_to(dir)
File.expand_path("../../../../#{dir}", __FILE__)
end
it 'adds `lib` to the load path' do
lib_dir = absolute_path_to("lib")
$LOAD_PATH.delete(lib_dir)
expect($LOAD_PATH).not_to include(lib_dir)
config.setup_load_path_and_require []
expect($LOAD_PATH).to include(lib_dir)
end
it 'adds the configured `default_path` to the load path' do
config.default_path = 'features'
foo_dir = absolute_path_to("features")
expect($LOAD_PATH).not_to include(foo_dir)
config.setup_load_path_and_require []
expect($LOAD_PATH).to include(foo_dir)
end
it 'stores the required files' do
config.should_receive(:require).with('a/path')
config.setup_load_path_and_require ['a/path']
expect(config.requires).to eq ['a/path']
end
context "when `default_path` refers to a file rather than a directory" do
it 'does not add it to the load path' do
config.default_path = 'Rakefile'
config.setup_load_path_and_require []
expect($LOAD_PATH).not_to include(match(/Rakefile/))
end
end
end
describe "#load_spec_files" do
it "loads files using load" do
config.files_to_run = ["foo.bar", "blah_spec.rb"]
config.should_receive(:load).twice
config.load_spec_files
end
it "loads each file once, even if duplicated in list" do
config.files_to_run = ["a_spec.rb", "a_spec.rb"]
config.should_receive(:load).once
config.load_spec_files
end
context "with rspec-1 loaded" do
before { stub_const("Spec::VERSION::MAJOR", 1) }
it "raises with a helpful message" do
expect {
config.load_spec_files
}.to raise_error(/rspec-1 has been loaded/)
end
end
end
describe "#treat_symbols_as_metadata_keys_with_true_values?" do
it 'defaults to false' do
expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be_false
end
it 'can be set to true' do
config.treat_symbols_as_metadata_keys_with_true_values = true
expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be_true
end
end
describe "#mock_framework" do
it "defaults to :rspec" do
config.should_receive(:require).with('rspec/core/mocking/with_rspec')
config.mock_framework
end
end
describe "#mock_framework="do
it "delegates to mock_with" do
config.should_receive(:mock_with).with(:rspec)
config.mock_framework = :rspec
end
end
shared_examples "a configurable framework adapter" do |m|
it "yields a config object if the framework_module supports it" do
custom_config = Struct.new(:custom_setting).new
mod = Module.new
mod.stub(:configuration => custom_config)
config.send m, mod do |mod_config|
mod_config.custom_setting = true
end
expect(custom_config.custom_setting).to be_true
end
it "raises if framework module doesn't support configuration" do
mod = Module.new
expect {
config.send m, mod do |mod_config|
end
}.to raise_error(/must respond to `configuration`/)
end
end
describe "#mock_with" do
before { config.stub(:require) }
it_behaves_like "a configurable framework adapter", :mock_with
[:rspec, :mocha, :rr, :flexmock].each do |framework|
context "with #{framework}" do
it "requires the adapter for #{framework}" do
config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
config.mock_with framework
end
end
end
it "allows rspec-mocks to be configured with a provided block" do
mod = Module.new
RSpec::Mocks.configuration.should_receive(:add_stub_and_should_receive_to).with(mod)
config.mock_with :rspec do |c|
c.add_stub_and_should_receive_to mod
end
end
context "with a module" do
it "sets the mock_framework_adapter to that module" do
mod = Module.new
config.mock_with mod
expect(config.mock_framework).to eq(mod)
end
end
it "uses the null adapter when set to any unknown key" do
config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
end
context 'when there are already some example groups defined' do
it 'raises an error since this setting must be applied before any groups are defined' do
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
expect {
config.mock_with :mocha
}.to raise_error(/must be configured before any example groups are defined/)
end
it 'does not raise an error if the default `mock_with :rspec` is re-configured' do
config.mock_framework # called by RSpec when configuring the first example group
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
config.mock_with :rspec
end
it 'does not raise an error if re-setting the same config' do
groups = []
RSpec.world.stub(:example_groups => groups)
config.mock_with :mocha
groups << double.as_null_object
config.mock_with :mocha
end
end
end
describe "#expectation_framework" do
it "defaults to :rspec" do
config.should_receive(:require).with('rspec/expectations')
config.expectation_frameworks
end
end
describe "#expectation_framework=" do
it "delegates to expect_with=" do
config.should_receive(:expect_with).with(:rspec)
config.expectation_framework = :rspec
end
end
describe "#expect_with" do
before do
stub_const("Test::Unit::Assertions", Module.new)
config.stub(:require)
end
it_behaves_like "a configurable framework adapter", :expect_with
[
[:rspec, 'rspec/expectations'],
[:stdlib, 'test/unit/assertions']
].each do |framework, required_file|
context "with #{framework}" do
it "requires #{required_file}" do
config.should_receive(:require).with(required_file)
config.expect_with framework
end
end
end
it "supports multiple calls" do
config.expect_with :rspec
config.expect_with :stdlib
expect(config.expectation_frameworks).to eq [RSpec::Matchers, Test::Unit::Assertions]
end
it "raises if block given with multiple args" do
expect {
config.expect_with :rspec, :stdlib do |mod_config|
end
}.to raise_error(/expect_with only accepts/)
end
it "raises ArgumentError if framework is not supported" do
expect do
config.expect_with :not_supported
end.to raise_error(ArgumentError)
end
context 'when there are already some example groups defined' do
it 'raises an error since this setting must be applied before any groups are defined' do
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
expect {
config.expect_with :rspec
}.to raise_error(/must be configured before any example groups are defined/)
end
it 'does not raise an error if the default `expect_with :rspec` is re-configured' do
config.expectation_frameworks # called by RSpec when configuring the first example group
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
config.expect_with :rspec
end
it 'does not raise an error if re-setting the same config' do
groups = []
RSpec.world.stub(:example_groups => groups)
config.expect_with :stdlib
groups << double.as_null_object
config.expect_with :stdlib
end
end
end
describe "#expecting_with_rspec?" do
before do
stub_const("Test::Unit::Assertions", Module.new)
config.stub(:require)
end
it "returns false by default" do
expect(config).not_to be_expecting_with_rspec
end
it "returns true when `expect_with :rspec` has been configured" do
config.expect_with :rspec
expect(config).to be_expecting_with_rspec
end
it "returns true when `expect_with :rspec, :stdlib` has been configured" do
config.expect_with :rspec, :stdlib
expect(config).to be_expecting_with_rspec
end
it "returns true when `expect_with :stdlib, :rspec` has been configured" do
config.expect_with :stdlib, :rspec
expect(config).to be_expecting_with_rspec
end
it "returns false when `expect_with :stdlib` has been configured" do
config.expect_with :stdlib
expect(config).not_to be_expecting_with_rspec
end
end
describe "#files_to_run" do
it "loads files not following pattern if named explicitly" do
config.files_or_directories_to_run = "spec/rspec/core/resources/a_bar.rb"
expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_bar.rb"])
end
it "prevents repetition of dir when start of the pattern" do
config.pattern = "spec/**/a_spec.rb"
config.files_or_directories_to_run = "spec"
expect(config.files_to_run).to eq(["spec/rspec/core/resources/a_spec.rb"])
end
it "does not prevent repetition of dir when later of the pattern" do
config.pattern = "rspec/**/a_spec.rb"
config.files_or_directories_to_run = "spec"
expect(config.files_to_run).to eq(["spec/rspec/core/resources/a_spec.rb"])
end
context "with :" do
it "overrides inclusion filters set on config" do
config.filter_run_including :foo => :bar
config.files_or_directories_to_run = "path/to/file.rb:37"
expect(config.inclusion_filter.size).to eq(1)
expect(config.inclusion_filter[:locations].keys.first).to match(/path\/to\/file\.rb$/)
expect(config.inclusion_filter[:locations].values.first).to eq([37])
end
it "overrides inclusion filters set before config" do
config.force(:inclusion_filter => {:foo => :bar})
config.files_or_directories_to_run = "path/to/file.rb:37"
expect(config.inclusion_filter.size).to eq(1)
expect(config.inclusion_filter[:locations].keys.first).to match(/path\/to\/file\.rb$/)
expect(config.inclusion_filter[:locations].values.first).to eq([37])
end
it "clears exclusion filters set on config" do
config.exclusion_filter = { :foo => :bar }
config.files_or_directories_to_run = "path/to/file.rb:37"
expect(config.exclusion_filter).to be_empty,
"expected exclusion filter to be empty:\n#{config.exclusion_filter}"
end
it "clears exclusion filters set before config" do
config.force(:exclusion_filter => { :foo => :bar })
config.files_or_directories_to_run = "path/to/file.rb:37"
expect(config.exclusion_filter).to be_empty,
"expected exclusion filter to be empty:\n#{config.exclusion_filter}"
end
end
context "with default pattern" do
it "loads files named _spec.rb" do
config.files_or_directories_to_run = "spec/rspec/core/resources"
expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_spec.rb"])
end
it "loads files in Windows", :if => RSpec.windows_os? do
config.files_or_directories_to_run = "C:\\path\\to\\project\\spec\\sub\\foo_spec.rb"
expect(config.files_to_run).to eq([ "C:/path/to/project/spec/sub/foo_spec.rb"])
end
it "loads files in Windows when directory is specified", :if => RSpec.windows_os? do
config.files_or_directories_to_run = "spec\\rspec\\core\\resources"
expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_spec.rb"])
end
end
context "with default default_path" do
it "loads files in the default path when run by rspec" do
config.stub(:command) { 'rspec' }
config.files_or_directories_to_run = []
expect(config.files_to_run).not_to be_empty
end
it "loads files in the default path when run with DRB (e.g., spork)" do
config.stub(:command) { 'spork' }
RSpec::Core::Runner.stub(:running_in_drb?) { true }
config.files_or_directories_to_run = []
expect(config.files_to_run).not_to be_empty
end
it "does not load files in the default path when run by ruby" do
config.stub(:command) { 'ruby' }
config.files_or_directories_to_run = []
expect(config.files_to_run).to be_empty
end
end
def specify_consistent_ordering_of_files_to_run
File.stub(:directory?).with('a') { true }
orderings = [
%w[ a/1.rb a/2.rb a/3.rb ],
%w[ a/2.rb a/1.rb a/3.rb ],
%w[ a/3.rb a/2.rb a/1.rb ]
].map do |files|
Dir.should_receive(:[]).with(/^\{?a/) { files }
yield
config.files_to_run
end
expect(orderings.uniq.size).to eq(1)
end
context 'when the given directories match the pattern' do
it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
specify_consistent_ordering_of_files_to_run do
config.pattern = 'a/*.rb'
config.files_or_directories_to_run = 'a'
end
end
end
context 'when the pattern is given relative to the given directories' do
it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
specify_consistent_ordering_of_files_to_run do
config.pattern = '*.rb'
config.files_or_directories_to_run = 'a'
end
end
end
context 'when given multiple file paths' do
it 'orders the files in a consistent ordering, regardless of the given order' do
File.stub(:directory?) { false } # fake it into thinking these a full file paths
files = ['a/b/c_spec.rb', 'c/b/a_spec.rb']
config.files_or_directories_to_run = *files
ordering_1 = config.files_to_run
config.files_or_directories_to_run = *(files.reverse)
ordering_2 = config.files_to_run
expect(ordering_1).to eq(ordering_2)
end
end
end
%w[pattern= filename_pattern=].each do |setter|
describe "##{setter}" do
context "with single pattern" do
before { config.send(setter, "**/*_foo.rb") }
it "loads files following pattern" do
file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
config.files_or_directories_to_run = file
expect(config.files_to_run).to include(file)
end
it "loads files in directories following pattern" do
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
config.files_or_directories_to_run = dir
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
end
it "does not load files in directories not following pattern" do
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
config.files_or_directories_to_run = dir
expect(config.files_to_run).not_to include("#{dir}/a_bar.rb")
end
end
context "with multiple patterns" do
it "supports comma separated values" do
config.send(setter, "**/*_foo.rb,**/*_bar.rb")
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
config.files_or_directories_to_run = dir
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
end
it "supports comma separated values with spaces" do
config.send(setter, "**/*_foo.rb, **/*_bar.rb")
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
config.files_or_directories_to_run = dir
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
end
it "supports curly braces glob syntax" do
config.send(setter, "**/*_{foo,bar}.rb")
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
config.files_or_directories_to_run = dir
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
end
end
end
end
describe "path with line number" do
it "assigns the line number as a location filter" do
config.files_or_directories_to_run = "path/to/a_spec.rb:37"
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
end
end
context "with full_description set" do
it "overrides filters" do
config.filter_run :focused => true
config.full_description = "foo"
expect(config.filter).not_to have_key(:focused)
end
it 'is possible to access the full description regular expression' do
config.full_description = "foo"
expect(config.full_description).to eq(/foo/)
end
end
context "without full_description having been set" do
it 'returns nil from #full_description' do
expect(config.full_description).to eq nil
end
end
context "with line number" do
it "assigns the file and line number as a location filter" do
config.files_or_directories_to_run = "path/to/a_spec.rb:37"
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
end
it "assigns multiple files with line numbers as location filters" do
config.files_or_directories_to_run = "path/to/a_spec.rb:37", "other_spec.rb:44"
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37],
File.expand_path("other_spec.rb") => [44]}})
end
it "assigns files with multiple line numbers as location filters" do
config.files_or_directories_to_run = "path/to/a_spec.rb:37", "path/to/a_spec.rb:44"
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37, 44]}})
end
end
context "with multiple line numbers" do
it "assigns the file and line numbers as a location filter" do
config.files_or_directories_to_run = "path/to/a_spec.rb:1:3:5:7"
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [1,3,5,7]}})
end
end
it "assigns the example name as the filter on description" do
config.full_description = "foo"
expect(config.filter).to eq({:full_description => /foo/})
end
it "assigns the example names as the filter on description if description is an array" do
config.full_description = [ "foo", "bar" ]
expect(config.filter).to eq({:full_description => Regexp.union(/foo/, /bar/)})
end
it 'is possible to access the full description regular expression' do
config.full_description = "foo","bar"
expect(config.full_description).to eq Regexp.union(/foo/,/bar/)
end
describe "#default_path" do
it 'defaults to "spec"' do
expect(config.default_path).to eq('spec')
end
end
describe "#include" do
module InstanceLevelMethods
def you_call_this_a_blt?
"egad man, where's the mayo?!?!?"
end
end
it_behaves_like "metadata hash builder" do
def metadata_hash(*args)
config.include(InstanceLevelMethods, *args)
config.include_or_extend_modules.last.last
end
end
context "with no filter" do
it "includes the given module into each example group" do
RSpec.configure do |c|
c.include(InstanceLevelMethods)
end
group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
expect(group).not_to respond_to(:you_call_this_a_blt?)
expect(group.new.you_call_this_a_blt?).to eq("egad man, where's the mayo?!?!?")
end
end
context "with a filter" do
it "includes the given module into each matching example group" do
RSpec.configure do |c|
c.include(InstanceLevelMethods, :magic_key => :include)
end
group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
expect(group).not_to respond_to(:you_call_this_a_blt?)
expect(group.new.you_call_this_a_blt?).to eq("egad man, where's the mayo?!?!?")
end
end
end
describe "#extend" do
module ThatThingISentYou
def that_thing
end
end
it_behaves_like "metadata hash builder" do
def metadata_hash(*args)
config.extend(ThatThingISentYou, *args)
config.include_or_extend_modules.last.last
end
end
it "extends the given module into each matching example group" do
RSpec.configure do |c|
c.extend(ThatThingISentYou, :magic_key => :extend)
end
group = ExampleGroup.describe(ThatThingISentYou, :magic_key => :extend) { }
expect(group).to respond_to(:that_thing)
end
end
describe "#run_all_when_everything_filtered?" do
it "defaults to false" do
expect(config.run_all_when_everything_filtered?).to be_false
end
it "can be queried with question method" do
config.run_all_when_everything_filtered = true
expect(config.run_all_when_everything_filtered?).to be_true
end
end
%w[color color_enabled].each do |color_option|
describe "##{color_option}=" do
context "given true" do
before { config.send "#{color_option}=", true }
context "with config.tty? and output.tty?" do
it "does not set color_enabled" do
output = StringIO.new
config.output_stream = output
config.tty = true
config.output_stream.stub :tty? => true
expect(config.send(color_option)).to be_true
expect(config.send(color_option, output)).to be_true
end
end
context "with config.tty? and !output.tty?" do
it "sets color_enabled" do
output = StringIO.new
config.output_stream = output
config.tty = true
config.output_stream.stub :tty? => false
expect(config.send(color_option)).to be_true
expect(config.send(color_option, output)).to be_true
end
end
context "with config.tty? and !output.tty?" do
it "does not set color_enabled" do
output = StringIO.new
config.output_stream = output
config.tty = false
config.output_stream.stub :tty? => true
expect(config.send(color_option)).to be_true
expect(config.send(color_option, output)).to be_true
end
end
context "with !config.tty? and !output.tty?" do
it "does not set color_enabled" do
output = StringIO.new
config.output_stream = output
config.tty = false
config.output_stream.stub :tty? => false
expect(config.send(color_option)).to be_false
expect(config.send(color_option, output)).to be_false
end
end
context "on windows" do
before do
@original_host = RbConfig::CONFIG['host_os']
RbConfig::CONFIG['host_os'] = 'mingw'
config.stub(:require)
config.stub(:warn)
end
after do
RbConfig::CONFIG['host_os'] = @original_host
end
context "with ANSICON available" do
around(:each) { |e| with_env_vars('ANSICON' => 'ANSICON', &e) }
it "enables colors" do
config.output_stream = StringIO.new
config.output_stream.stub :tty? => true
config.send "#{color_option}=", true
expect(config.send(color_option)).to be_true
end
it "leaves output stream intact" do
config.output_stream = $stdout
config.stub(:require) do |what|
config.output_stream = 'foo' if what =~ /Win32/
end
config.send "#{color_option}=", true
expect(config.output_stream).to eq($stdout)
end
end
context "with ANSICON NOT available" do
it "warns to install ANSICON" do
config.stub(:require) { raise LoadError }
config.should_receive(:warn).
with(/You must use ANSICON/)
config.send "#{color_option}=", true
end
it "sets color_enabled to false" do
config.stub(:require) { raise LoadError }
config.send "#{color_option}=", true
config.color_enabled = true
expect(config.send(color_option)).to be_false
end
end
end
end
end
it "prefers incoming cli_args" do
config.output_stream = StringIO.new
config.output_stream.stub :tty? => true
config.force :color => true
config.color = false
expect(config.color).to be_true
end
end
describe '#formatter=' do
it "delegates to add_formatter (better API for user-facing configuration)" do
config.should_receive(:add_formatter).with('these','options')
config.add_formatter('these','options')
end
end
describe "#add_formatter" do
it "adds to the list of formatters" do
config.add_formatter :documentation
expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
end
it "finds a formatter by name (w/ Symbol)" do
config.add_formatter :documentation
expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
end
it "finds a formatter by name (w/ String)" do
config.add_formatter 'documentation'
expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
end
it "finds a formatter by class" do
formatter_class = Class.new(Formatters::BaseTextFormatter)
config.add_formatter formatter_class
expect(config.formatters.first).to be_an_instance_of(formatter_class)
end
it "finds a formatter by class name" do
stub_const("CustomFormatter", Class.new(Formatters::BaseFormatter))
config.add_formatter "CustomFormatter"
expect(config.formatters.first).to be_an_instance_of(CustomFormatter)
end
it "finds a formatter by class fully qualified name" do
stub_const("RSpec::CustomFormatter", Class.new(Formatters::BaseFormatter))
config.add_formatter "RSpec::CustomFormatter"
expect(config.formatters.first).to be_an_instance_of(RSpec::CustomFormatter)
end
it "requires a formatter file based on its fully qualified name" do
config.should_receive(:require).with('rspec/custom_formatter') do
stub_const("RSpec::CustomFormatter", Class.new(Formatters::BaseFormatter))
end
config.add_formatter "RSpec::CustomFormatter"
expect(config.formatters.first).to be_an_instance_of(RSpec::CustomFormatter)
end
it "raises NameError if class is unresolvable" do
config.should_receive(:require).with('rspec/custom_formatter3')
expect(lambda { config.add_formatter "RSpec::CustomFormatter3" }).to raise_error(NameError)
end
it "raises ArgumentError if formatter is unknown" do
expect(lambda { config.add_formatter :progresss }).to raise_error(ArgumentError)
end
context "with a 2nd arg defining the output" do
it "creates a file at that path and sets it as the output" do
path = File.join(Dir.tmpdir, 'output.txt')
config.add_formatter('doc', path)
expect(config.formatters.first.output).to be_a(File)
expect(config.formatters.first.output.path).to eq(path)
end
end
end
describe "#filter_run_including" do
it_behaves_like "metadata hash builder" do
def metadata_hash(*args)
config.filter_run_including(*args)
config.inclusion_filter
end
end
it "sets the filter with a hash" do
config.filter_run_including :foo => true
expect(config.inclusion_filter[:foo]).to be(true)
end
it "sets the filter with a symbol" do
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
config.filter_run_including :foo
expect(config.inclusion_filter[:foo]).to be(true)
end
it "merges with existing filters" do
config.filter_run_including :foo => true
config.filter_run_including :bar => false
expect(config.inclusion_filter[:foo]).to be(true)
expect(config.inclusion_filter[:bar]).to be(false)
end
end
describe "#filter_run_excluding" do
it_behaves_like "metadata hash builder" do
def metadata_hash(*args)
config.filter_run_excluding(*args)
config.exclusion_filter
end
end
it "sets the filter" do
config.filter_run_excluding :foo => true
expect(config.exclusion_filter[:foo]).to be(true)
end
it "sets the filter using a symbol" do
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
config.filter_run_excluding :foo
expect(config.exclusion_filter[:foo]).to be(true)
end
it "merges with existing filters" do
config.filter_run_excluding :foo => true
config.filter_run_excluding :bar => false
expect(config.exclusion_filter[:foo]).to be(true)
expect(config.exclusion_filter[:bar]).to be(false)
end
end
describe "#inclusion_filter" do
it "returns {} even if set to nil" do
config.inclusion_filter = nil
expect(config.inclusion_filter).to eq({})
end
end
describe "#inclusion_filter=" do
it "treats symbols as hash keys with true values when told to" do
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
config.inclusion_filter = :foo
expect(config.inclusion_filter).to eq({:foo => true})
end
it "overrides any inclusion filters set on the command line or in configuration files" do
config.force(:inclusion_filter => { :foo => :bar })
config.inclusion_filter = {:want => :this}
expect(config.inclusion_filter).to eq({:want => :this})
end
end
describe "#exclusion_filter" do
it "returns {} even if set to nil" do
config.exclusion_filter = nil
expect(config.exclusion_filter).to eq({})
end
describe "the default :if filter" do
it "does not exclude a spec with { :if => true } metadata" do
expect(config.exclusion_filter[:if].call(true)).to be_false
end
it "excludes a spec with { :if => false } metadata" do
expect(config.exclusion_filter[:if].call(false)).to be_true
end
it "excludes a spec with { :if => nil } metadata" do
expect(config.exclusion_filter[:if].call(nil)).to be_true
end
end
describe "the default :unless filter" do
it "excludes a spec with { :unless => true } metadata" do
expect(config.exclusion_filter[:unless].call(true)).to be_true
end
it "does not exclude a spec with { :unless => false } metadata" do
expect(config.exclusion_filter[:unless].call(false)).to be_false
end
it "does not exclude a spec with { :unless => nil } metadata" do
expect(config.exclusion_filter[:unless].call(nil)).to be_false
end
end
end
describe "#exclusion_filter=" do
it "treats symbols as hash keys with true values when told to" do
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
config.exclusion_filter = :foo
expect(config.exclusion_filter).to eq({:foo => true})
end
it "overrides any exclusion filters set on the command line or in configuration files" do
config.force(:exclusion_filter => { :foo => :bar })
config.exclusion_filter = {:want => :this}
expect(config.exclusion_filter).to eq({:want => :this})
end
end
describe "line_numbers=" do
before { config.filter_manager.stub(:warn) }
it "sets the line numbers" do
config.line_numbers = ['37']
expect(config.filter).to eq({:line_numbers => [37]})
end
it "overrides filters" do
config.filter_run :focused => true
config.line_numbers = ['37']
expect(config.filter).to eq({:line_numbers => [37]})
end
it "prevents subsequent filters" do
config.line_numbers = ['37']
config.filter_run :focused => true
expect(config.filter).to eq({:line_numbers => [37]})
end
end
describe "line_numbers" do
it "returns the line numbers from the filter" do
config.line_numbers = ['42']
expect(config.line_numbers).to eq [42]
end
it "defaults to empty" do
expect(config.line_numbers).to eq []
end
end
describe "#full_backtrace=" do
context "given true" do
it "clears the backtrace exclusion patterns" do
config.full_backtrace = true
expect(config.backtrace_exclusion_patterns).to eq([])
end
end
context "given false" do
it "restores backtrace clean patterns" do
config.full_backtrace = false
expect(config.backtrace_exclusion_patterns).to eq(RSpec::Core::BacktraceCleaner::DEFAULT_EXCLUSION_PATTERNS)
end
end
it "doesn't impact other instances of config" do
config_1 = Configuration.new
config_2 = Configuration.new
config_1.full_backtrace = true
expect(config_2.backtrace_exclusion_patterns).not_to be_empty
end
end
describe "#backtrace_clean_patterns=" do
it "actually receives the new filter values" do
RSpec.stub(:deprecate)
config = Configuration.new
config.backtrace_clean_patterns = [/.*/]
expect(config.backtrace_cleaner.exclude? "this").to be_true
end
end
describe 'full_backtrace' do
it 'returns true when backtrace patterns is empty' do
config.backtrace_exclusion_patterns = []
expect(config.full_backtrace?).to eq true
end
it 'returns false when backtrace patterns isnt empty' do
config.backtrace_exclusion_patterns = [:lib]
expect(config.full_backtrace?).to eq false
end
end
describe "#backtrace_clean_patterns" do
before { allow(RSpec).to receive(:deprecate) }
it "is deprecated" do
RSpec.should_receive(:deprecate)
config = Configuration.new
config.backtrace_clean_patterns
end
it "can be appended to" do
config = Configuration.new
config.backtrace_clean_patterns << /.*/
expect(config.backtrace_cleaner.exclude? "this").to be_true
end
end
describe ".backtrace_cleaner#exclude? defaults" do
it "returns true for rspec files" do
expect(config.backtrace_cleaner.exclude?("lib/rspec/core.rb")).to be_true
end
it "returns true for spec_helper" do
expect(config.backtrace_cleaner.exclude?("spec/spec_helper.rb")).to be_true
end
it "returns true for java files (for JRuby)" do
expect(config.backtrace_cleaner.exclude?("org/jruby/RubyArray.java:2336")).to be_true
end
it "returns true for files within installed gems" do
expect(config.backtrace_cleaner.exclude?('ruby-1.8.7-p334/gems/mygem-2.3.0/lib/mygem.rb')).to be_true
end
it "returns false for files in projects containing 'gems' in the name" do
expect(config.backtrace_cleaner.exclude?('code/my-gems-plugin/lib/plugin.rb')).to be_false
end
it "returns false for something in the current working directory" do
expect(config.backtrace_cleaner.exclude?("#{Dir.getwd}/arbitrary")).to be_false
end
end
describe "#debug=true" do
before do
if defined?(Debugger)
@orig_debugger = Debugger
Object.send(:remove_const, :Debugger)
else
@orig_debugger = nil
end
config.stub(:require)
Object.const_set("Debugger", debugger)
end
after do
Object.send(:remove_const, :Debugger)
Object.const_set("Debugger", @orig_debugger) if @orig_debugger
end
let(:debugger) { double('Debugger').as_null_object }
it "requires 'ruby-debug'" do
config.should_receive(:require).with('ruby-debug')
config.debug = true
end
it "starts the debugger" do
debugger.should_receive(:start)
config.debug = true
end
end
describe "#debug=false" do
it "does not require 'ruby-debug'" do
config.should_not_receive(:require).with('ruby-debug')
config.debug = false
end
end
describe "#debug?" do
it 'returns true if the debugger has been loaded' do
stub_const("Debugger", Object.new)
expect(config.debug?).to be_true
end
it 'returns false if the debugger has not been loaded' do
hide_const("Debugger")
expect(config.debug?).to be_false
end
end
describe "#output=" do
it "sets the output" do
output = double("output")
config.output = output
expect(config.output).to equal(output)
end
end
describe "#libs=" do
include_context "isolate load path mutation"
it "adds directories to the LOAD_PATH" do
$LOAD_PATH.should_receive(:unshift).with("a/dir")
config.libs = ["a/dir"]
end
end
describe "libs" do
include_context "isolate load path mutation"
it 'records paths added to the load path' do
config.libs = ["a/dir"]
expect(config.libs).to eq ["a/dir"]
end
end
describe "#requires=" do
before { RSpec.should_receive :deprecate }
it "requires the configured files" do
config.should_receive(:require).with('foo').ordered
config.should_receive(:require).with('bar').ordered
config.requires = ['foo', 'bar']
end
it "stores require paths" do
config.should_receive(:require).with("a/path")
config.requires = ["a/path"]
expect(config.requires).to eq ['a/path']
end
end
describe "#add_setting" do
describe "with no modifiers" do
context "with no additional options" do
before do
config.add_setting :custom_option
end
it "defaults to nil" do
expect(config.custom_option).to be_nil
end
it "adds a predicate" do
expect(config.custom_option?).to be_false
end
it "can be overridden" do
config.custom_option = "a value"
expect(config.custom_option).to eq("a value")
end
end
context "with :default => 'a value'" do
before do
config.add_setting :custom_option, :default => 'a value'
end
it "defaults to 'a value'" do
expect(config.custom_option).to eq("a value")
end
it "returns true for the predicate" do
expect(config.custom_option?).to be_true
end
it "can be overridden with a truthy value" do
config.custom_option = "a new value"
expect(config.custom_option).to eq("a new value")
end
it "can be overridden with nil" do
config.custom_option = nil
expect(config.custom_option).to eq(nil)
end
it "can be overridden with false" do
config.custom_option = false
expect(config.custom_option).to eq(false)
end
end
end
context "with :alias => " do
it "is deprecated" do
RSpec::should_receive(:deprecate).with(/:alias option/, :replacement => ":alias_with")
config.add_setting :custom_option
config.add_setting :another_custom_option, :alias => :custom_option
end
end
context "with :alias_with => " do
before do
config.add_setting :custom_option, :alias_with => :another_custom_option
end
it "delegates the getter to the other option" do
config.another_custom_option = "this value"
expect(config.custom_option).to eq("this value")
end
it "delegates the setter to the other option" do
config.custom_option = "this value"
expect(config.another_custom_option).to eq("this value")
end
it "delegates the predicate to the other option" do
config.custom_option = true
expect(config.another_custom_option?).to be_true
end
end
end
describe "#configure_group" do
it "extends with 'extend'" do
mod = Module.new
group = ExampleGroup.describe("group", :foo => :bar)
config.extend(mod, :foo => :bar)
config.configure_group(group)
expect(group).to be_a(mod)
end
it "extends with 'module'" do
mod = Module.new
group = ExampleGroup.describe("group", :foo => :bar)
config.include(mod, :foo => :bar)
config.configure_group(group)
expect(group.included_modules).to include(mod)
end
it "requires only one matching filter" do
mod = Module.new
group = ExampleGroup.describe("group", :foo => :bar)
config.include(mod, :foo => :bar, :baz => :bam)
config.configure_group(group)
expect(group.included_modules).to include(mod)
end
it "includes each one before deciding whether to include the next" do
mod1 = Module.new do
def self.included(host)
host.metadata[:foo] = :bar
end
end
mod2 = Module.new
group = ExampleGroup.describe("group")
config.include(mod1)
config.include(mod2, :foo => :bar)
config.configure_group(group)
expect(group.included_modules).to include(mod1)
expect(group.included_modules).to include(mod2)
end
module IncludeOrExtendMeOnce
def self.included(host)
raise "included again" if host.instance_methods.include?(:foobar)
host.class_eval { def foobar; end }
end
def self.extended(host)
raise "extended again" if host.respond_to?(:foobar)
def host.foobar; end
end
end
it "doesn't include a module when already included in ancestor" do
config.include(IncludeOrExtendMeOnce, :foo => :bar)
group = ExampleGroup.describe("group", :foo => :bar)
child = group.describe("child")
config.configure_group(group)
config.configure_group(child)
end
it "doesn't extend when ancestor is already extended with same module" do
config.extend(IncludeOrExtendMeOnce, :foo => :bar)
group = ExampleGroup.describe("group", :foo => :bar)
child = group.describe("child")
config.configure_group(group)
config.configure_group(child)
end
end
describe "#alias_example_to" do
it_behaves_like "metadata hash builder" do
after do
RSpec::Core::ExampleGroup.module_eval do
class << self
undef :my_example_method if method_defined? :my_example_method
end
end
end
def metadata_hash(*args)
config.alias_example_to :my_example_method, *args
group = ExampleGroup.describe("group")
example = group.my_example_method("description")
example.metadata
end
end
end
describe "#reset" do
it "clears the reporter" do
expect(config.reporter).not_to be_nil
config.reset
expect(config.instance_variable_get("@reporter")).to be_nil
end
it "clears the formatters" do
config.add_formatter "doc"
config.reset
expect(config.formatters).to be_empty
end
end
describe "#force" do
it "forces order" do
config.force :order => "default"
config.order = "rand"
expect(config.order).to eq("default")
end
it "forces order and seed with :order => 'rand:37'" do
config.force :order => "rand:37"
config.order = "default"
expect(config.order).to eq("rand")
expect(config.seed).to eq(37)
end
it "forces order and seed with :seed => '37'" do
config.force :seed => "37"
config.order = "default"
expect(config.seed).to eq(37)
expect(config.order).to eq("rand")
end
it 'can set random ordering' do
config.force :seed => "rand:37"
RSpec.stub(:configuration => config)
list = [1, 2, 3, 4].extend(Extensions::Ordered::Examples)
Kernel.should_receive(:rand).and_return(3, 1, 4, 2)
expect(list.ordered).to eq([2, 4, 1, 3])
end
it "forces 'false' value" do
config.add_setting :custom_option
config.custom_option = true
expect(config.custom_option?).to be_true
config.force :custom_option => false
expect(config.custom_option?).to be_false
config.custom_option = true
expect(config.custom_option?).to be_false
end
end
describe '#seed' do
it 'returns the seed as an int' do
config.seed = '123'
expect(config.seed).to eq(123)
end
end
describe '#randomize?' do
context 'with order set to :random' do
before { config.order = :random }
it 'returns true' do
expect(config.randomize?).to be_true
end
end
context 'with order set to nil' do
before { config.order = nil }
it 'returns false' do
expect(config.randomize?).to be_false
end
end
end
describe '#order=' do
context 'given "random:123"' do
before { config.order = 'random:123' }
it 'sets order to "random"' do
expect(config.order).to eq('random')
end
it 'sets seed to 123' do
expect(config.seed).to eq(123)
end
it 'sets up random ordering' do
RSpec.stub(:configuration => config)
list = [1, 2, 3, 4].extend(Extensions::Ordered::Examples)
Kernel.should_receive(:rand).and_return(3, 1, 4, 2)
expect(list.ordered).to eq([2, 4, 1, 3])
end
end
context 'given "default"' do
before do
config.order = 'rand:123'
config.order = 'default'
end
it "sets the order to nil" do
expect(config.order).to be_nil
end
it "sets the seed to nil" do
expect(config.seed).to be_nil
end
it 'clears the random ordering' do
RSpec.stub(:configuration => config)
list = [1, 2, 3, 4].extend(Extensions::Ordered::Examples)
Kernel.should_not_receive(:rand)
expect(list.ordered).to eq([1, 2, 3, 4])
end
end
end
describe "#order_examples" do
before { RSpec.stub(:configuration => config) }
it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::Examples' do
examples = [1, 2, 3, 4]
examples.extend Extensions::Ordered::Examples
config.order_examples { |examples_to_order| examples_to_order.reverse }
expect(examples.ordered).to eq([4, 3, 2, 1])
end
it 'sets #order to "custom"' do
config.order_examples { |examples| examples.reverse }
expect(config.order).to eq("custom")
end
end
describe "#example_ordering_block" do
it 'defaults to a block that returns the passed argument' do
expect(config.example_ordering_block.call([1, 2, 3])).to eq([1, 2, 3])
end
end
describe "#order_groups" do
before { RSpec.stub(:configuration => config) }
it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::ExampleGroups' do
groups = [1, 2, 3, 4]
groups.extend Extensions::Ordered::ExampleGroups
config.order_groups { |groups_to_order| groups_to_order.reverse }
expect(groups.ordered).to eq([4, 3, 2, 1])
end
it 'sets #order to "custom"' do
config.order_groups { |groups| groups.reverse }
expect(config.order).to eq("custom")
end
end
describe "#group_ordering_block" do
it 'defaults to a block that returns the passed argument' do
expect(config.group_ordering_block.call([1, 2, 3])).to eq([1, 2, 3])
end
end
describe "#order_groups_and_examples" do
let(:examples) { [1, 2, 3, 4].extend Extensions::Ordered::Examples }
let(:groups) { [1, 2, 3, 4].extend Extensions::Ordered::ExampleGroups }
before do
RSpec.stub(:configuration => config)
config.order_groups_and_examples { |list| list.reverse }
end
it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::Examples' do
expect(examples.ordered).to eq([4, 3, 2, 1])
end
it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::ExampleGroups' do
expect(groups.ordered).to eq([4, 3, 2, 1])
end
end
describe '#warnings' do
around do |example|
@_original_setting = $VERBOSE
example.run
$VERBOSE = @_original_setting
end
it "sets verbose to true when true" do
config.warnings = true
expect($VERBOSE).to eq true
end
it "sets verbose to false when true" do
config.warnings = false
expect($VERBOSE).to eq false
end
it 'returns the verbosity setting' do
expect(config.warnings).to eq $VERBOSE
end
it 'is loaded from config by #force' do
config.force :warnings => true
expect($VERBOSE).to eq true
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/shared_example_group/ 0000755 0000041 0000041 00000000000 12261207027 023071 5 ustar www-data www-data rspec-core-2.14.7/spec/rspec/core/shared_example_group/collection_spec.rb 0000644 0000041 0000041 00000003716 12261207027 026572 0 ustar www-data www-data require 'spec_helper'
module RSpec::Core::SharedExampleGroup
describe Collection do
# this represents:
#
# shared_examples "top level group"
#
# context do
# shared_examples "nested level one"
# end
#
# context do
# shared_examples "nested level two"
# end
#
let(:examples) do
Hash.new { |hash,k| hash[k] = Hash.new }.tap do |hash|
hash["main"] = { "top level group" => example_1 }
hash["nested 1"] = { "nested level one" => example_2 }
hash["nested 2"] = { "nested level two" => example_3 }
end
end
(1..3).each { |num| let("example_#{num}") { double "example #{num}" } }
context 'setup with one source, which is the top level' do
let(:collection) { Collection.new ['main'], examples }
it 'fetches examples from the top level' do
expect(collection['top level group']).to eq example_1
end
it 'fetches examples across the nested context' do
RSpec.stub(:warn_deprecation)
expect(collection['nested level two']).to eq example_3
end
it 'warns about deprecation when you fetch across nested contexts' do
RSpec.should_receive(:warn_deprecation)
collection['nested level two']
end
end
context 'setup with multiple sources' do
let(:collection) { Collection.new ['main','nested 1'], examples }
it 'fetches examples from the context' do
expect(collection['nested level one']).to eq example_2
end
it 'fetches examples from main' do
expect(collection['top level group']).to eq example_1
end
it 'fetches examples across the nested context' do
RSpec.stub(:warn_deprecation)
expect(collection['nested level two']).to eq example_3
end
it 'warns about deprecation when you fetch across nested contexts' do
RSpec.should_receive(:warn_deprecation)
collection['nested level two']
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/command_line_spec_output.txt 0000644 0000041 0000041 00000000000 12261207027 024502 0 ustar www-data www-data rspec-core-2.14.7/spec/rspec/core/reporter_spec.rb 0000644 0000041 0000041 00000010072 12261207027 022075 0 ustar www-data www-data require "spec_helper"
module RSpec::Core
describe Reporter do
describe "abort" do
let(:formatter) { double("formatter") }
let(:example) { double("example") }
let(:reporter) { Reporter.new(formatter) }
%w[start_dump dump_pending dump_failures dump_summary close].each do |message|
it "sends #{message} to the formatter(s) that respond to message" do
formatter.should_receive(message)
reporter.abort(nil)
end
it "doesnt notify formatters about messages they dont implement" do
expect { reporter.abort(nil) }.to_not raise_error
end
end
end
context "given one formatter" do
it "passes messages to that formatter" do
formatter = double("formatter", :example_started => nil)
example = double("example")
reporter = Reporter.new(formatter)
formatter.should_receive(:example_started).
with(example)
reporter.example_started(example)
end
it "passes example_group_started and example_group_finished messages to that formatter in that order" do
order = []
formatter = double("formatter")
formatter.stub(:example_group_started) { |group| order << "Started: #{group.description}" }
formatter.stub(:example_group_finished) { |group| order << "Finished: #{group.description}" }
group = ExampleGroup.describe("root")
group.describe("context 1") do
example("ignore") {}
end
group.describe("context 2") do
example("ignore") {}
end
group.run(Reporter.new(formatter))
expect(order).to eq([
"Started: root",
"Started: context 1",
"Finished: context 1",
"Started: context 2",
"Finished: context 2",
"Finished: root"
])
end
end
context "given an example group with no examples" do
it "does not pass example_group_started or example_group_finished to formatter" do
formatter = double("formatter")
formatter.should_not_receive(:example_group_started)
formatter.should_not_receive(:example_group_finished)
group = ExampleGroup.describe("root")
group.run(Reporter.new(formatter))
end
end
context "given multiple formatters" do
it "passes messages to all formatters" do
formatters = (1..2).map { double("formatter", :example_started => nil) }
example = double("example")
reporter = Reporter.new(*formatters)
formatters.each do |formatter|
formatter.
should_receive(:example_started).
with(example)
end
reporter.example_started(example)
end
end
describe "#report" do
it "supports one arg (count)" do
Reporter.new.report(1) {}
end
it "supports two args (count, seed)" do
Reporter.new.report(1, 2) {}
end
it "yields itself" do
reporter = Reporter.new
yielded = nil
reporter.report(3) {|r| yielded = r}
expect(yielded).to eq(reporter)
end
end
describe "#register_listener" do
let(:reporter) { Reporter.new }
let(:listener) { double("listener", :start => nil) }
before { reporter.register_listener listener, :start }
it 'will register the listener to specified notifications' do
expect(reporter.registered_listeners :start).to eq [listener]
end
it 'will send notifications when a subscribed event is triggered' do
listener.should_receive(:start).with(42)
reporter.start 42
end
end
describe "timing" do
it "uses RSpec::Core::Time as to not be affected by changes to time in examples" do
formatter = double(:formatter)
duration = nil
formatter.stub(:dump_summary) do |dur, _, _, _|
duration = dur
end
reporter = Reporter.new formatter
reporter.start 1
Time.stub(:now => ::Time.utc(2012, 10, 1))
reporter.finish 1234
expect(duration).to be < 0.2
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/hooks_filtering_spec.rb 0000644 0000041 0000041 00000020703 12261207027 023423 0 ustar www-data www-data require "spec_helper"
module RSpec::Core
describe "config block hook filtering" do
describe "unfiltered hooks" do
it "is run" do
filters = []
RSpec.configure do |c|
c.before(:all) { filters << "before all in config"}
c.around(:each) {|example| filters << "around each in config"; example.run}
c.before(:each) { filters << "before each in config"}
c.after(:each) { filters << "after each in config"}
c.after(:all) { filters << "after all in config"}
end
group = ExampleGroup.describe
group.example("example") {}
group.run
expect(filters).to eq([
"before all in config",
"around each in config",
"before each in config",
"after each in config",
"after all in config"
])
end
end
describe "hooks with single filters" do
context "with no scope specified" do
it "is run around|before|after :each if the filter matches the example group's filter" do
filters = []
RSpec.configure do |c|
c.around(:match => true) {|example| filters << "around each in config"; example.run}
c.before(:match => true) { filters << "before each in config"}
c.after(:match => true) { filters << "after each in config"}
end
group = ExampleGroup.describe(:match => true)
group.example("example") {}
group.run
expect(filters).to eq([
"around each in config",
"before each in config",
"after each in config"
])
end
end
it "is run if the filter matches the example group's filter" do
filters = []
RSpec.configure do |c|
c.before(:all, :match => true) { filters << "before all in config"}
c.around(:each, :match => true) {|example| filters << "around each in config"; example.run}
c.before(:each, :match => true) { filters << "before each in config"}
c.after(:each, :match => true) { filters << "after each in config"}
c.after(:all, :match => true) { filters << "after all in config"}
end
group = ExampleGroup.describe(:match => true)
group.example("example") {}
group.run
expect(filters).to eq([
"before all in config",
"around each in config",
"before each in config",
"after each in config",
"after all in config"
])
end
it "runs before|after :all hooks on matching nested example groups" do
filters = []
RSpec.configure do |c|
c.before(:all, :match => true) { filters << :before_all }
c.after(:all, :match => true) { filters << :after_all }
end
example_1_filters = example_2_filters = nil
group = ExampleGroup.describe "group" do
it("example 1") { example_1_filters = filters.dup }
describe "subgroup", :match => true do
it("example 2") { example_2_filters = filters.dup }
end
end
group.run
expect(example_1_filters).to be_empty
expect(example_2_filters).to eq([:before_all])
expect(filters).to eq([:before_all, :after_all])
end
it "runs before|after :all hooks only on the highest level group that matches the filter" do
filters = []
RSpec.configure do |c|
c.before(:all, :match => true) { filters << :before_all }
c.after(:all, :match => true) { filters << :after_all }
end
example_1_filters = example_2_filters = example_3_filters = nil
group = ExampleGroup.describe "group", :match => true do
it("example 1") { example_1_filters = filters.dup }
describe "subgroup", :match => true do
it("example 2") { example_2_filters = filters.dup }
describe "sub-subgroup", :match => true do
it("example 3") { example_3_filters = filters.dup }
end
end
end
group.run
expect(example_1_filters).to eq([:before_all])
expect(example_2_filters).to eq([:before_all])
expect(example_3_filters).to eq([:before_all])
expect(filters).to eq([:before_all, :after_all])
end
it "does not run if the filter doesn't match the example group's filter" do
filters = []
RSpec.configure do |c|
c.before(:all, :match => false) { filters << "before all in config"}
c.around(:each, :match => false) {|example| filters << "around each in config"; example.run}
c.before(:each, :match => false) { filters << "before each in config"}
c.after(:each, :match => false) { filters << "after each in config"}
c.after(:all, :match => false) { filters << "after all in config"}
end
group = ExampleGroup.describe(:match => true)
group.example("example") {}
group.run
expect(filters).to eq([])
end
context "when the hook filters apply to individual examples instead of example groups" do
let(:each_filters) { [] }
let(:all_filters) { [] }
let(:group) do
md = example_metadata
ExampleGroup.describe do
it("example", md) { }
end
end
def filters
each_filters + all_filters
end
before(:each) do
af, ef = all_filters, each_filters
RSpec.configure do |c|
c.before(:all, :foo => :bar) { af << "before all in config"}
c.around(:each, :foo => :bar) {|example| ef << "around each in config"; example.run}
c.before(:each, :foo => :bar) { ef << "before each in config"}
c.after(:each, :foo => :bar) { ef << "after each in config"}
c.after(:all, :foo => :bar) { af << "after all in config"}
end
group.run
end
describe 'an example with matching metadata' do
let(:example_metadata) { { :foo => :bar } }
it "runs the `:each` hooks" do
expect(each_filters).to eq([
'around each in config',
'before each in config',
'after each in config'
])
end
it "does not run the `:all` hooks" do
expect(all_filters).to be_empty
end
end
describe 'an example without matching metadata' do
let(:example_metadata) { { :foo => :bazz } }
it "does not run any of the hooks" do
expect(filters).to be_empty
end
end
end
end
describe "hooks with multiple filters" do
it "is run if all hook filters match the group's filters" do
filters = []
RSpec.configure do |c|
c.before(:all, :one => 1) { filters << "before all in config"}
c.around(:each, :two => 2, :one => 1) {|example| filters << "around each in config"; example.run}
c.before(:each, :one => 1, :two => 2) { filters << "before each in config"}
c.after(:each, :one => 1, :two => 2, :three => 3) { filters << "after each in config"}
c.after(:all, :one => 1, :three => 3) { filters << "after all in config"}
end
group = ExampleGroup.describe(:one => 1, :two => 2, :three => 3)
group.example("example") {}
group.run
expect(filters).to eq([
"before all in config",
"around each in config",
"before each in config",
"after each in config",
"after all in config"
])
end
it "does not run if some hook filters don't match the group's filters" do
filters = []
RSpec.configure do |c|
c.before(:all, :one => 1, :four => 4) { filters << "before all in config"}
c.around(:each, :two => 2, :four => 4) {|example| filters << "around each in config"; example.run}
c.before(:each, :one => 1, :two => 2, :four => 4) { filters << "before each in config"}
c.after(:each, :one => 1, :two => 2, :three => 3, :four => 4) { filters << "after each in config"}
c.after(:all, :one => 1, :three => 3, :four => 4) { filters << "after all in config"}
end
group = ExampleGroup.describe(:one => 1, :two => 2, :three => 3)
group.example("example") {}
group.run
expect(filters).to eq([])
end
end
end
end
rspec-core-2.14.7/spec/rspec/core/metadata_spec.rb 0000644 0000041 0000041 00000045610 12261207027 022021 0 ustar www-data www-data require 'spec_helper'
module RSpec
module Core
describe Metadata do
describe '.relative_path' do
let(:here) { File.expand_path(".") }
it "transforms absolute paths to relative paths" do
expect(Metadata.relative_path(here)).to eq "."
end
it "transforms absolute paths to relative paths anywhere in its argument" do
expect(Metadata.relative_path("foo #{here} bar")).to eq "foo . bar"
end
it "returns nil if passed an unparseable file:line combo" do
expect(Metadata.relative_path("-e:1")).to be_nil
end
# I have no idea what line = line.sub(/\A([^:]+:\d+)$/, '\\1') is supposed to do
it "gracefully returns nil if run in a secure thread" do
safely do
value = Metadata.relative_path(".")
# on some rubies, File.expand_path is not a security error, so accept "." as well
expect([nil, "."]).to include(value)
end
end
end
describe "#process" do
Metadata::RESERVED_KEYS.each do |key|
it "prohibits :#{key} as a hash key" do
m = Metadata.new
expect do
m.process('group', key => {})
end.to raise_error(/:#{key} is not allowed/)
end
end
it "uses :caller if passed as part of the user metadata" do
m = Metadata.new
m.process('group', :caller => ['example_file:42'])
expect(m[:example_group][:location]).to eq("example_file:42")
end
end
describe "#filter_applies?" do
let(:parent_group_metadata) { Metadata.new.process('parent group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
let(:group_metadata) { Metadata.new(parent_group_metadata).process('group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
let(:example_metadata) { group_metadata.for_example('example', :caller => ["foo_spec.rb:#{__LINE__}"], :if => true) }
let(:next_example_metadata) { group_metadata.for_example('next_example', :caller => ["foo_spec.rb:#{example_line_number + 2}"]) }
let(:world) { World.new }
before { RSpec.stub(:world) { world } }
shared_examples_for "matching by line number" do
let(:preceeding_declaration_lines) {{
parent_group_metadata[:example_group][:line_number] => parent_group_metadata[:example_group][:line_number],
group_metadata[:example_group][:line_number] => group_metadata[:example_group][:line_number],
example_metadata[:line_number] => example_metadata[:line_number],
(example_metadata[:line_number] + 1) => example_metadata[:line_number],
(example_metadata[:line_number] + 2) => example_metadata[:line_number] + 2,
}}
before do
world.should_receive(:preceding_declaration_line).at_least(:once).and_return do |v|
preceeding_declaration_lines[v]
end
end
it "matches the group when the line_number is the example group line number" do
# this call doesn't really make sense since filter_applies? is only called
# for example metadata not group metadata
expect(group_metadata.filter_applies?(condition_key, group_condition)).to be_true
end
it "matches the example when the line_number is the grandparent example group line number" do
expect(example_metadata.filter_applies?(condition_key, parent_group_condition)).to be_true
end
it "matches the example when the line_number is the parent example group line number" do
expect(example_metadata.filter_applies?(condition_key, group_condition)).to be_true
end
it "matches the example when the line_number is the example line number" do
expect(example_metadata.filter_applies?(condition_key, example_condition)).to be_true
end
it "matches when the line number is between this example and the next" do
expect(example_metadata.filter_applies?(condition_key, between_examples_condition)).to be_true
end
it "does not match when the line number matches the next example" do
expect(example_metadata.filter_applies?(condition_key, next_example_condition)).to be_false
end
end
context "with a single line number" do
let(:condition_key){ :line_numbers }
let(:parent_group_condition) { [parent_group_metadata[:example_group][:line_number]] }
let(:group_condition) { [group_metadata[:example_group][:line_number]] }
let(:example_condition) { [example_metadata[:line_number]] }
let(:between_examples_condition) { [group_metadata[:example_group][:line_number] + 1] }
let(:next_example_condition) { [example_metadata[:line_number] + 2] }
it_has_behavior "matching by line number"
end
context "with multiple line numbers" do
let(:condition_key){ :line_numbers }
let(:parent_group_condition) { [-1, parent_group_metadata[:example_group][:line_number]] }
let(:group_condition) { [-1, group_metadata[:example_group][:line_number]] }
let(:example_condition) { [-1, example_metadata[:line_number]] }
let(:between_examples_condition) { [-1, group_metadata[:example_group][:line_number] + 1] }
let(:next_example_condition) { [-1, example_metadata[:line_number] + 2] }
it_has_behavior "matching by line number"
end
context "with locations" do
let(:condition_key){ :locations }
let(:parent_group_condition) do
{File.expand_path(parent_group_metadata[:example_group][:file_path]) => [parent_group_metadata[:example_group][:line_number]]}
end
let(:group_condition) do
{File.expand_path(group_metadata[:example_group][:file_path]) => [group_metadata[:example_group][:line_number]]}
end
let(:example_condition) do
{File.expand_path(example_metadata[:file_path]) => [example_metadata[:line_number]]}
end
let(:between_examples_condition) do
{File.expand_path(group_metadata[:example_group][:file_path]) => [group_metadata[:example_group][:line_number] + 1]}
end
let(:next_example_condition) do
{File.expand_path(example_metadata[:file_path]) => [example_metadata[:line_number] + 2]}
end
it_has_behavior "matching by line number"
it "ignores location filters for other files" do
expect(example_metadata.filter_applies?(:locations, {"/path/to/other_spec.rb" => [3,5,7]})).to be_true
end
end
it "matches a proc with no arguments that evaluates to true" do
expect(example_metadata.filter_applies?(:if, lambda { true })).to be_true
end
it "matches a proc that evaluates to true" do
expect(example_metadata.filter_applies?(:if, lambda { |v| v })).to be_true
end
it "does not match a proc that evaluates to false" do
expect(example_metadata.filter_applies?(:if, lambda { |v| !v })).to be_false
end
it "matches a proc with an arity of 2" do
example_metadata[:foo] = nil
expect(example_metadata.filter_applies?(:foo, lambda { |v, m| m == example_metadata })).to be_true
end
it "raises an error when the proc has an incorrect arity" do
expect {
example_metadata.filter_applies?(:if, lambda { |a,b,c| true })
}.to raise_error(ArgumentError)
end
context "with an Array" do
let(:metadata_with_array) {
group_metadata.for_example('example_with_array', :tag => [:one, 2, 'three', /four/])
}
it "matches a symbol" do
expect(metadata_with_array.filter_applies?(:tag, 'one')).to be_true
expect(metadata_with_array.filter_applies?(:tag, :one)).to be_true
expect(metadata_with_array.filter_applies?(:tag, 'two')).to be_false
end
it "matches a string" do
expect(metadata_with_array.filter_applies?(:tag, 'three')).to be_true
expect(metadata_with_array.filter_applies?(:tag, :three)).to be_true
expect(metadata_with_array.filter_applies?(:tag, 'tree')).to be_false
end
it "matches an integer" do
expect(metadata_with_array.filter_applies?(:tag, '2')).to be_true
expect(metadata_with_array.filter_applies?(:tag, 2)).to be_true
expect(metadata_with_array.filter_applies?(:tag, 3)).to be_false
end
it "matches a regexp" do
expect(metadata_with_array.filter_applies?(:tag, 'four')).to be_true
expect(metadata_with_array.filter_applies?(:tag, 'fourtune')).to be_true
expect(metadata_with_array.filter_applies?(:tag, 'fortune')).to be_false
end
it "matches a proc that evaluates to true" do
expect(metadata_with_array.filter_applies?(:tag, lambda { |values| values.include? 'three' })).to be_true
end
it "does not match a proc that evaluates to false" do
expect(metadata_with_array.filter_applies?(:tag, lambda { |values| values.include? 'nothing' })).to be_false
end
end
end
describe "#for_example" do
let(:metadata) { Metadata.new.process("group description") }
let(:mfe) { metadata.for_example("example description", {:arbitrary => :options}) }
let(:line_number) { __LINE__ - 1 }
it "stores the description args" do
expect(mfe.fetch(:description_args)).to eq ["example description"]
expect(mfe[:description_args]).to eq ["example description"]
end
it "ignores nil description args" do
expect(metadata.for_example(nil, {}).fetch(:description_args)).to eq []
expect(metadata.for_example(nil, {})[:description_args]).to eq []
end
it "stores the full_description (group description + example description)" do
expect(mfe.fetch(:full_description)).to eq("group description example description")
expect(mfe[:full_description]).to eq("group description example description")
end
it "creates an empty execution result" do
expect(mfe.fetch(:execution_result)).to eq({})
expect(mfe[:execution_result]).to eq({})
end
it "extracts file path from caller" do
expect(mfe.fetch(:file_path)).to eq(relative_path(__FILE__))
expect(mfe[:file_path]).to eq(relative_path(__FILE__))
end
it "extracts line number from caller" do
expect(mfe.fetch(:line_number)).to eq(line_number)
expect(mfe[:line_number]).to eq(line_number)
end
it "extracts location from caller" do
expect(mfe.fetch(:location)).to eq("#{relative_path(__FILE__)}:#{line_number}")
expect(mfe[:location]).to eq("#{relative_path(__FILE__)}:#{line_number}")
end
it "uses :caller if passed as an option" do
example_metadata = metadata.for_example('example description', {:caller => ['example_file:42']})
expect(example_metadata[:location]).to eq("example_file:42")
end
it "merges arbitrary options" do
expect(mfe.fetch(:arbitrary)).to eq(:options)
expect(mfe[:arbitrary]).to eq(:options)
end
it "points :example_group to the same hash object" do
a = metadata.for_example("foo", {})[:example_group]
b = metadata.for_example("bar", {})[:example_group]
a[:description] = "new description"
expect(b[:description]).to eq("new description")
end
end
[:described_class, :describes].each do |key|
describe key do
context "with a String" do
it "returns nil" do
m = Metadata.new
m.process('group')
expect(m[:example_group][key]).to be_nil
end
end
context "with a Symbol" do
it "returns nil" do
m = Metadata.new
m.process(:group)
expect(m[:example_group][key]).to be_nil
end
end
context "with a class" do
it "returns the class" do
m = Metadata.new
m.process(String)
expect(m[:example_group][key]).to be(String)
end
end
context "in a nested group" do
it "returns the parent group's described class" do
sm = Metadata.new
sm.process(String)
m = Metadata.new(sm)
m.process(Array)
expect(m[:example_group][key]).to be(String)
end
it "returns own described class if parent doesn't have one" do
sm = Metadata.new
sm.process("foo")
m = Metadata.new(sm)
m.process(Array)
expect(m[:example_group][key]).to be(Array)
end
it "can override a parent group's described class" do
parent = Metadata.new
parent.process(String)
child = Metadata.new(parent)
child.process(Fixnum)
child[:example_group][key] = Hash
grandchild = Metadata.new(child)
grandchild.process(Array)
expect(grandchild[:example_group][key]).to be(Hash)
expect(child[:example_group][key]).to be(Hash)
expect(parent[:example_group][key]).to be(String)
end
end
end
end
describe ":description" do
it "just has the example description" do
m = Metadata.new
m.process("group")
m = m.for_example("example", {})
expect(m[:description]).to eq("example")
end
context "with a string" do
it "provides the submitted description" do
m = Metadata.new
m.process("group")
expect(m[:example_group][:description]).to eq("group")
end
end
context "with a non-string" do
it "provides the submitted description" do
m = Metadata.new
m.process("group")
expect(m[:example_group][:description]).to eq("group")
end
end
context "with a non-string and a string" do
it "concats the args" do
m = Metadata.new
m.process(Object, 'group')
expect(m[:example_group][:description]).to eq("Object group")
end
end
context "with empty args" do
it "returns empty string for [:example_group][:description]" do
m = Metadata.new
m.process()
expect(m[:example_group][:description]).to eq("")
end
end
end
describe ":full_description" do
it "concats example group name and description" do
group_metadata = Metadata.new
group_metadata.process('group')
example_metadata = group_metadata.for_example("example", {})
expect(example_metadata[:full_description]).to eq("group example")
end
it "concats nested example group descriptions" do
parent = Metadata.new
parent.process('parent')
child = Metadata.new(parent)
child.process('child')
expect(child[:example_group][:full_description]).to eq("parent child")
expect(child.for_example('example', child)[:full_description]).to eq("parent child example")
end
it "concats nested example group descriptions three deep" do
grandparent = Metadata.new
grandparent.process('grandparent')
parent = Metadata.new(grandparent)
parent.process('parent')
child = Metadata.new(parent)
child.process('child')
expect(grandparent[:example_group][:full_description]).to eq("grandparent")
expect(parent[:example_group][:full_description]).to eq("grandparent parent")
expect(child[:example_group][:full_description]).to eq("grandparent parent child")
expect(child.for_example('example', child)[:full_description]).to eq("grandparent parent child example")
end
%w[# . ::].each do |char|
context "with a 2nd arg starting with #{char}" do
it "removes the space" do
m = Metadata.new
m.process(Array, "#{char}method")
expect(m[:example_group][:full_description]).to eq("Array#{char}method")
end
end
context "with a description starting with #{char} nested under a module" do
it "removes the space" do
parent = Metadata.new
parent.process(Object)
child = Metadata.new(parent)
child.process("#{char}method")
expect(child[:example_group][:full_description]).to eq("Object#{char}method")
end
end
context "with a description starting with #{char} nested under a context string" do
it "does not remove the space" do
grandparent = Metadata.new
grandparent.process(Array)
parent = Metadata.new(grandparent)
parent.process("with 2 items")
child = Metadata.new(parent)
child.process("#{char}method")
expect(child[:example_group][:full_description]).to eq("Array with 2 items #{char}method")
end
end
end
end
describe ":file_path" do
it "finds the first non-rspec lib file in the caller array" do
m = Metadata.new
m.process(:caller => [
"./lib/rspec/core/foo.rb",
"#{__FILE__}:#{__LINE__}"
])
expect(m[:example_group][:file_path]).to eq(relative_path(__FILE__))
end
end
describe ":line_number" do
it "finds the line number with the first non-rspec lib file in the backtrace" do
m = Metadata.new
m.process({})
expect(m[:example_group][:line_number]).to eq(__LINE__ - 1)
end
it "finds the line number with the first spec file with drive letter" do
m = Metadata.new
m.process(:caller => [ "C:/path/to/file_spec.rb:#{__LINE__}" ])
expect(m[:example_group][:line_number]).to eq(__LINE__ - 1)
end
it "uses the number after the first : for ruby 1.9" do
m = Metadata.new
m.process(:caller => [ "#{__FILE__}:#{__LINE__}:999" ])
expect(m[:example_group][:line_number]).to eq(__LINE__ - 1)
end
end
describe "child example group" do
it "nests the parent's example group metadata" do
parent = Metadata.new
parent.process(Object, 'parent')
child = Metadata.new(parent)
child.process()
expect(child[:example_group][:example_group]).to eq(parent[:example_group])
end
end
end
end
end
rspec-core-2.14.7/spec/rspec/core_spec.rb 0000644 0000041 0000041 00000003656 12261207027 020245 0 ustar www-data www-data require 'spec_helper'
describe RSpec do
describe "::configuration" do
it "returns the same object every time" do
expect(RSpec.configuration).to equal(RSpec.configuration)
end
end
describe "::configuration=" do
it "sets the configuration object" do
configuration = RSpec::Core::Configuration.new
RSpec.configuration = configuration
expect(RSpec.configuration).to equal(configuration)
end
end
describe "::configure" do
it "yields the current configuration" do
RSpec.configure do |config|
expect(config).to equal(RSpec::configuration)
end
end
end
describe "::world" do
it "returns the same object every time" do
expect(RSpec.world).to equal(RSpec.world)
end
end
describe "::world=" do
it "sets the world object" do
world = RSpec::Core::World.new
RSpec.world = world
expect(RSpec.world).to equal(world)
end
end
describe "::reset" do
it "resets the configuration and world objects" do
config_before_reset = RSpec.configuration
world_before_reset = RSpec.world
RSpec.reset
expect(RSpec.configuration).not_to equal(config_before_reset)
expect(RSpec.world).not_to equal(world_before_reset)
end
end
# This is hard to test :(. Best way I could come up with was starting
# fresh ruby process w/o this stuff already loaded.
it "loads mocks and expectations when the constants are referenced" do
code = "$LOAD_PATH.replace(#{$LOAD_PATH.inspect}); " +
'require "rspec"; ' +
"puts RSpec::Mocks.name; " +
"puts RSpec::Expectations.name"
result = `ruby -e '#{code}'`.chomp
expect(result.split("\n")).to eq(%w[ RSpec::Mocks RSpec::Expectations ])
end
it 'correctly raises an error when an invalid const is referenced' do
expect {
RSpec::NotAConst
}.to raise_error(NameError, /uninitialized constant RSpec::NotAConst/)
end
end
rspec-core-2.14.7/spec/support/ 0000755 0000041 0000041 00000000000 12261207027 016344 5 ustar www-data www-data rspec-core-2.14.7/spec/support/sandboxed_mock_space.rb 0000644 0000041 0000041 00000005216 12261207027 023030 0 ustar www-data www-data require 'rspec/mocks'
module RSpec
module Core
# Because rspec-core dog-foods itself, rspec-core's spec suite has
# examples that define example groups and examples and run them. The
# usual lifetime of an RSpec::Mocks::Proxy is for one example
# (the proxy cache gets cleared between each example), but since the
# specs in rspec-core's suite sometimes create test doubles and pass
# them to examples a spec defines and runs, the test double's proxy
# must live beyond the inner example: it must live for the scope
# of wherever it got defined. Here we implement the necessary semantics
# for rspec-core's specs:
#
# - #verify_all and #reset_all affect only mocks that were created
# within the current scope.
# - Mock proxies live for the duration of the scope in which they are
# created.
#
# Thus, mock proxies created in an inner example live for only that
# example, but mock proxies created in an outer example can be used
# in an inner example but will only be reset/verified when the outer
# example completes.
class SandboxedMockSpace < ::RSpec::Mocks::Space
def self.sandboxed
orig_space = RSpec::Mocks.space
RSpec::Mocks.space = RSpec::Core::SandboxedMockSpace.new
RSpec::Core::Example.class_eval do
alias_method :orig_run, :run
def run(*args)
RSpec::Mocks.space.sandboxed do
orig_run(*args)
end
end
end
yield
ensure
RSpec::Core::Example.class_eval do
remove_method :run
alias_method :run, :orig_run
remove_method :orig_run
end
RSpec::Mocks.space = orig_space
end
class Sandbox
attr_reader :proxies
def initialize
@proxies = Set.new
end
def verify_all
@proxies.each { |p| p.verify }
end
def reset_all
@proxies.each { |p| p.reset }
end
end
def initialize
@sandbox_stack = []
super
end
def sandboxed
@sandbox_stack << Sandbox.new
yield
ensure
@sandbox_stack.pop
end
def verify_all
return super unless sandbox = @sandbox_stack.last
sandbox.verify_all
end
def reset_all
return super unless sandbox = @sandbox_stack.last
sandbox.reset_all
end
def proxy_for(object)
new_proxy = !proxies.has_key?(object.__id__)
proxy = super
if new_proxy && sandbox = @sandbox_stack.last
sandbox.proxies << proxy
end
proxy
end
end
end
end
rspec-core-2.14.7/spec/support/matchers.rb 0000644 0000041 0000041 00000003264 12261207027 020504 0 ustar www-data www-data RSpec::Matchers.define :map_specs do |specs|
match do |autotest|
@specs = specs
@autotest = prepare(autotest)
autotest.test_files_for(@file) == specs
end
chain :to do |file|
@file = file
end
failure_message_for_should do
"expected #{@autotest.class} to map #{@specs.inspect} to #{@file.inspect}\ngot #{@actual.inspect}"
end
def prepare(autotest)
find_order = @specs.dup << @file
autotest.instance_eval { @find_order = find_order }
autotest
end
end
RSpec::Matchers.define :fail_with do |exception_klass|
match do |example|
failure_reason(example, exception_klass).nil?
end
failure_message_for_should do |example|
"expected example to fail with a #{exception_klass} exception, but #{failure_reason(example, exception_klass)}"
end
def failure_reason(example, exception_klass)
result = example.metadata[:execution_result]
case
when example.metadata[:pending] then "was pending"
when result[:status] != 'failed' then result[:status]
when !result[:exception].is_a?(exception_klass) then "failed with a #{result[:exception].class}"
else nil
end
end
end
RSpec::Matchers.define :pass do
match do |example|
failure_reason(example).nil?
end
failure_message_for_should do |example|
"expected example to pass, but #{failure_reason(example)}"
end
def failure_reason(example)
result = example.metadata[:execution_result]
case
when example.metadata[:pending] then "was pending"
when result[:status] != 'passed' then result[:status]
else nil
end
end
end
RSpec::Matchers.module_eval do
alias_method :have_failed_with, :fail_with
alias_method :have_passed, :pass
end
rspec-core-2.14.7/spec/support/isolated_directory.rb 0000644 0000041 0000041 00000000311 12261207027 022554 0 ustar www-data www-data require 'tmpdir'
require 'fileutils'
shared_context "isolated directory", :isolated_directory => true do
around do |ex|
Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir, &ex)
end
end
end
rspec-core-2.14.7/spec/support/mathn_integration_support.rb 0000644 0000041 0000041 00000000273 12261207027 024201 0 ustar www-data www-data require 'support/in_sub_process'
module MathnIntegrationSupport
include InSubProcess
def with_mathn_loaded
in_sub_process do
require 'mathn'
yield
end
end
end
rspec-core-2.14.7/spec/support/spec_files.rb 0000644 0000041 0000041 00000001671 12261207027 021012 0 ustar www-data www-data shared_context "spec files" do
def failing_spec_filename
@failing_spec_filename ||= File.expand_path(File.dirname(__FILE__)) + "/_failing_spec.rb"
end
def passing_spec_filename
@passing_spec_filename ||= File.expand_path(File.dirname(__FILE__)) + "/_passing_spec.rb"
end
def create_passing_spec_file
File.open(passing_spec_filename, 'w') do |f|
f.write %q{
describe "passing spec" do
it "passes" do
expect(1).to eq(1)
end
end
}
end
end
def create_failing_spec_file
File.open(failing_spec_filename, 'w') do |f|
f.write %q{
describe "failing spec" do
it "fails" do
expect(1).to eq(2)
end
end
}
end
end
before(:all) do
create_passing_spec_file
create_failing_spec_file
end
after(:all) do
File.delete(passing_spec_filename)
File.delete(failing_spec_filename)
end
end
rspec-core-2.14.7/spec/support/shared_example_groups.rb 0000644 0000041 0000041 00000002641 12261207027 023254 0 ustar www-data www-data shared_examples_for "metadata hash builder" do
context "when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to true" do
let(:hash) { metadata_hash(:foo, :bar, :bazz => 23) }
before(:each) do
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = true }
end
it 'treats symbols as metadata keys with a true value' do
expect(hash[:foo]).to be(true)
expect(hash[:bar]).to be(true)
end
it 'still processes hash values normally' do
expect(hash[:bazz]).to be(23)
end
end
context "when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to false" do
let(:warning_receiver) { Kernel }
before(:each) do
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = false }
warning_receiver.stub(:warn)
end
it 'prints a deprecation warning about any symbols given as arguments' do
warning_receiver.should_receive(:warn).with(/In RSpec 3, these symbols will be treated as metadata keys/)
metadata_hash(:foo, :bar, :key => 'value')
end
it 'does not treat symbols as metadata keys' do
expect(metadata_hash(:foo, :bar, :key => 'value')).not_to include(:foo, :bar)
end
it 'does not print a warning if there are no symbol arguments' do
warning_receiver.should_not_receive(:warn)
metadata_hash(:foo => 23, :bar => 17)
end
end
end
rspec-core-2.14.7/spec/support/config_options_helper.rb 0000644 0000041 0000041 00000000501 12261207027 023244 0 ustar www-data www-data module ConfigOptionsHelper
extend RSpec::SharedContext
around(:each) { |e| without_env_vars('SPEC_OPTS', &e) }
def config_options_object(*args)
coo = RSpec::Core::ConfigurationOptions.new(args)
coo.parse_options
coo
end
def parse_options(*args)
config_options_object(*args).options
end
end
rspec-core-2.14.7/spec/support/isolated_home_directory.rb 0000644 0000041 0000041 00000000502 12261207027 023566 0 ustar www-data www-data require 'tmpdir'
require 'fileutils'
shared_context "isolated home directory", :isolated_home => true do
around do |ex|
Dir.mktmpdir do |tmp_dir|
original_home = ENV['HOME']
begin
ENV['HOME'] = tmp_dir
ex.call
ensure
ENV['HOME'] = original_home
end
end
end
end
rspec-core-2.14.7/spec/support/isolate_load_path_mutation.rb 0000644 0000041 0000041 00000000264 12261207027 024266 0 ustar www-data www-data shared_context "isolate load path mutation" do
original_load_path = nil
before { original_load_path = $LOAD_PATH.dup }
after { $LOAD_PATH.replace(original_load_path) }
end
rspec-core-2.14.7/spec/support/helper_methods.rb 0000644 0000041 0000041 00000001440 12261207027 021672 0 ustar www-data www-data module RSpecHelpers
def relative_path(path)
RSpec::Core::Metadata.relative_path(path)
end
def ignoring_warnings
original = $VERBOSE
$VERBOSE = nil
result = yield
$VERBOSE = original
result
end
def safely
Thread.new do
ignoring_warnings { $SAFE = 3 }
yield
end.join
# $SAFE is not supported on Rubinius
unless defined?(Rubinius)
expect($SAFE).to eql 0 # $SAFE should not have changed in this thread.
end
end
def expect_deprecation_with_call_site(file, line)
expect(RSpec.configuration.reporter).to receive(:deprecation) do |options|
expect(options[:call_site]).to include([file, line].join(':'))
end
end
def allow_deprecation
allow(RSpec.configuration.reporter).to receive(:deprecation)
end
end
rspec-core-2.14.7/spec/support/in_sub_process.rb 0000644 0000041 0000041 00000001447 12261207027 021714 0 ustar www-data www-data module InSubProcess
if RUBY_PLATFORM == 'java'
def in_sub_process
pending "This spec requires forking to work properly, " +
"and JRuby does not support forking"
end
else
# Useful as a way to isolate a global change to a subprocess.
def in_sub_process
readme, writeme = IO.pipe
pid = Process.fork do
exception = nil
begin
yield
rescue Exception => e
exception = e
end
writeme.write Marshal.dump(exception)
readme.close
writeme.close
exit! # prevent at_exit hooks from running (e.g. minitest)
end
writeme.close
Process.waitpid(pid)
exception = Marshal.load(readme.read)
readme.close
raise exception if exception
end
end
end
rspec-core-2.14.7/lib/ 0000755 0000041 0000041 00000000000 12261207027 014444 5 ustar www-data www-data rspec-core-2.14.7/lib/autotest/ 0000755 0000041 0000041 00000000000 12261207027 016314 5 ustar www-data www-data rspec-core-2.14.7/lib/autotest/rspec2.rb 0000644 0000041 0000041 00000004024 12261207027 020037 0 ustar www-data www-data require 'autotest'
require 'rspec/core/deprecation'
# Derived from the `Autotest` class, extends the `autotest` command to work
# with RSpec.
#
# @note this will be extracted to a separate gem when we release rspec-3.
class Autotest::Rspec2 < Autotest
RSPEC_EXECUTABLE = File.expand_path('../../../exe/rspec', __FILE__)
def initialize
super()
clear_mappings
setup_rspec_project_mappings
# Example for Ruby 1.8: http://rubular.com/r/AOXNVDrZpx
# Example for Ruby 1.9: http://rubular.com/r/85ag5AZ2jP
self.failed_results_re = /^\s*\d+\).*\n\s+(?:\e\[\d*m)?Failure.*(\n(?:\e\[\d*m)?\s+#\s(.*)?:\d+(?::.*)?(?:\e\[\d*m)?)+$/m
self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
end
# Adds conventional spec-to-file mappings to Autotest configuation.
def setup_rspec_project_mappings
add_mapping(%r%^spec/.*_spec\.rb$%) { |filename, _|
filename
}
add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
["spec/#{m[1]}_spec.rb"]
}
add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
files_matching %r%^spec/.*_spec\.rb$%
}
end
# Overrides Autotest's implementation to read rspec output
def consolidate_failures(failed)
filters = new_hash_of_arrays
failed.each do |spec, trace|
if trace =~ /(.*spec\.rb)/
filters[$1] << spec
end
end
return filters
end
# Overrides Autotest's implementation to generate the rspec command to run
def make_test_cmd(files_to_test)
files_to_test.empty? ? '' :
%|#{prefix}"#{ruby}"#{suffix} -S "#{RSPEC_EXECUTABLE}" --tty #{normalize(files_to_test).keys.flatten.map { |f| %|"#{f}"|}.join(' ')}|
end
# Generates a map of filenames to Arrays for Autotest
def normalize(files_to_test)
files_to_test.keys.inject({}) do |result, filename|
result.merge!(File.expand_path(filename) => [])
end
end
private
def suffix
using_bundler? ? "" : defined?(:Gem) ? " -rrubygems" : ""
end
def using_bundler?
prefix =~ /bundle exec/
end
def gemfile?
File.exist?('./Gemfile')
end
end
rspec-core-2.14.7/lib/autotest/discover.rb 0000644 0000041 0000041 00000000077 12261207027 020463 0 ustar www-data www-data Autotest.add_discovery { "rspec2" } if File.exist?("./.rspec")
rspec-core-2.14.7/lib/rspec/ 0000755 0000041 0000041 00000000000 12261207027 015560 5 ustar www-data www-data rspec-core-2.14.7/lib/rspec/core/ 0000755 0000041 0000041 00000000000 12261207027 016510 5 ustar www-data www-data rspec-core-2.14.7/lib/rspec/core/project_initializer.rb 0000644 0000041 0000041 00000004536 12261207027 023116 0 ustar www-data www-data module RSpec
module Core
class ProjectInitializer
def initialize(arg=nil)
@arg = arg
end
def run
create_spec_helper_file
create_dot_rspec_file
delete_if_confirmed("autotest/discover.rb", <<-MESSAGE)
RSpec registers its own discover.rb with Autotest, so autotest/discover.rb is
no longer needed.
MESSAGE
delete_if_confirmed("lib/tasks/rspec.rake", <<-MESSAGE)
If the file in lib/tasks/rspec.rake is the one generated by rspec-rails-1x,
you can get rid of it, as it is no longer needed with rspec-2.
MESSAGE
end
def create_dot_rspec_file
if File.exist?('.rspec')
report_exists('.rspec')
else
report_creating('.rspec')
File.open('.rspec','w') do |f|
f.write <<-CONTENT
--color
--format progress
CONTENT
end
end
end
def create_spec_helper_file
if File.exist?('spec/spec_helper.rb')
report_exists("spec/spec_helper.rb")
else
report_creating("spec/spec_helper.rb")
FileUtils.mkdir_p('spec')
File.open('spec/spec_helper.rb','w') do |f|
f.write <<-CONTENT
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
end
CONTENT
end
end
end
def delete_if_confirmed(path, message)
if File.exist?(path)
puts
puts message
puts
puts " delete #{path}? [y/n]"
FileUtils.rm_rf(path) if gets =~ /y/i
end
end
def report_exists(file)
puts " exist #{file}"
end
def report_creating(file)
puts " create #{file}"
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/filter_manager.rb 0000644 0000041 0000041 00000014512 12261207027 022017 0 ustar www-data www-data module RSpec
module Core
# Manages the filtering of examples and groups by matching tags declared on
# the command line or options files, or filters declared via
# `RSpec.configure`, with hash key/values submitted within example group
# and/or example declarations. For example, given this declaration:
#
# describe Thing, :awesome => true do
# it "does something" do
# # ...
# end
# end
#
# That group (or any other with `:awesome => true`) would be filtered in
# with any of the following commands:
#
# rspec --tag awesome:true
# rspec --tag awesome
# rspec -t awesome:true
# rspec -t awesome
#
# Prefixing the tag names with `~` negates the tags, thus excluding this group with
# any of:
#
# rspec --tag ~awesome:true
# rspec --tag ~awesome
# rspec -t ~awesome:true
# rspec -t ~awesome
#
# ## Options files and command line overrides
#
# Tag declarations can be stored in `.rspec`, `~/.rspec`, or a custom
# options file. This is useful for storing defaults. For example, let's
# say you've got some slow specs that you want to suppress most of the
# time. You can tag them like this:
#
# describe Something, :slow => true do
#
# And then store this in `.rspec`:
#
# --tag ~slow:true
#
# Now when you run `rspec`, that group will be excluded.
#
# ## Overriding
#
# Of course, you probably want to run them sometimes, so you can override
# this tag on the command line like this:
#
# rspec --tag slow:true
#
# ## RSpec.configure
#
# You can also store default tags with `RSpec.configure`. We use `tag` on
# the command line (and in options files like `.rspec`), but for historical
# reasons we use the term `filter` in `RSpec.configure:
#
# RSpec.configure do |c|
# c.filter_run_including :foo => :bar
# c.filter_run_excluding :foo => :bar
# end
#
# These declarations can also be overridden from the command line.
#
# @see RSpec.configure
# @see Configuration#filter_run_including
# @see Configuration#filter_run_excluding
class FilterManager
DEFAULT_EXCLUSIONS = {
:if => lambda { |value| !value },
:unless => lambda { |value| value }
}
STANDALONE_FILTERS = [:locations, :line_numbers, :full_description]
module Describable
PROC_HEX_NUMBER = /0x[0-9a-f]+@/
PROJECT_DIR = File.expand_path('.')
def description
reject { |k, v| RSpec::Core::FilterManager::DEFAULT_EXCLUSIONS[k] == v }.inspect.gsub(PROC_HEX_NUMBER, '').gsub(PROJECT_DIR, '.').gsub(' (lambda)','')
end
def empty_without_conditional_filters?
reject { |k, v| RSpec::Core::FilterManager::DEFAULT_EXCLUSIONS[k] == v }.empty?
end
end
module BackwardCompatibility
def merge(orig, opposite, *updates)
_warn_deprecated_keys(updates.last)
super
end
def reverse_merge(orig, opposite, *updates)
_warn_deprecated_keys(updates.last)
super
end
# Supports a use case that probably doesn't exist: overriding the
# if/unless procs.
def _warn_deprecated_keys(updates)
_warn_deprecated_key(:unless, updates) if updates.has_key?(:unless)
_warn_deprecated_key(:if, updates) if updates.has_key?(:if)
end
# Emits a deprecation warning for keys that will not be supported in
# the future.
def _warn_deprecated_key(key, updates)
RSpec.deprecate("FilterManager#exclude(#{key.inspect} => #{updates[key].inspect})")
@exclusions[key] = updates.delete(key)
end
end
attr_reader :exclusions, :inclusions
def initialize
@exclusions = DEFAULT_EXCLUSIONS.dup.extend(Describable)
@inclusions = {}.extend(Describable)
extend(BackwardCompatibility)
end
def add_location(file_path, line_numbers)
# locations is a hash of expanded paths to arrays of line
# numbers to match against. e.g.
# { "path/to/file.rb" => [37, 42] }
locations = @inclusions.delete(:locations) || Hash.new {|h,k| h[k] = []}
locations[File.expand_path(file_path)].push(*line_numbers)
@inclusions.replace(:locations => locations)
@exclusions.clear
end
def empty?
inclusions.empty? && exclusions.empty_without_conditional_filters?
end
def prune(examples)
examples.select {|e| !exclude?(e) && include?(e)}
end
def exclude(*args)
merge(@exclusions, @inclusions, *args)
end
def exclude!(*args)
replace(@exclusions, @inclusions, *args)
end
def exclude_with_low_priority(*args)
reverse_merge(@exclusions, @inclusions, *args)
end
def exclude?(example)
@exclusions.empty? ? false : example.any_apply?(@exclusions)
end
def include(*args)
unless_standalone(*args) { merge(@inclusions, @exclusions, *args) }
end
def include!(*args)
unless_standalone(*args) { replace(@inclusions, @exclusions, *args) }
end
def include_with_low_priority(*args)
unless_standalone(*args) { reverse_merge(@inclusions, @exclusions, *args) }
end
def include?(example)
@inclusions.empty? ? true : example.any_apply?(@inclusions)
end
private
def unless_standalone(*args)
is_standalone_filter?(args.last) ? @inclusions.replace(args.last) : yield unless already_set_standalone_filter?
end
def merge(orig, opposite, *updates)
orig.merge!(updates.last).each_key {|k| opposite.delete(k)}
end
def replace(orig, opposite, *updates)
updates.last.each_key {|k| opposite.delete(k)}
orig.replace(updates.last)
end
def reverse_merge(orig, opposite, *updates)
updated = updates.last.merge(orig)
opposite.each_pair {|k,v| updated.delete(k) if updated[k] == v}
orig.replace(updated)
end
def already_set_standalone_filter?
is_standalone_filter?(inclusions)
end
def is_standalone_filter?(filter)
STANDALONE_FILTERS.any? {|key| filter.has_key?(key)}
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/configuration.rb 0000644 0000041 0000041 00000113351 12261207027 021710 0 ustar www-data www-data require 'fileutils'
require 'rspec/core/backtrace_cleaner'
require 'rspec/core/ruby_project'
require 'rspec/core/formatters/deprecation_formatter.rb'
module RSpec
module Core
# Stores runtime configuration information.
#
# Configuration options are loaded from `~/.rspec`, `.rspec`,
# `.rspec-local`, command line switches, and the `SPEC_OPTS` environment
# variable (listed in lowest to highest precedence; for example, an option
# in `~/.rspec` can be overridden by an option in `.rspec-local`).
#
# @example Standard settings
# RSpec.configure do |c|
# c.drb = true
# c.drb_port = 1234
# c.default_path = 'behavior'
# end
#
# @example Hooks
# RSpec.configure do |c|
# c.before(:suite) { establish_connection }
# c.before(:each) { log_in_as :authorized }
# c.around(:each) { |ex| Database.transaction(&ex) }
# end
#
# @see RSpec.configure
# @see Hooks
class Configuration
include RSpec::Core::Hooks
class MustBeConfiguredBeforeExampleGroupsError < StandardError; end
# @private
def self.define_reader(name)
define_method(name) do
variable = instance_variable_defined?("@#{name}") ? instance_variable_get("@#{name}") : nil
value_for(name, variable)
end
end
# @private
def self.deprecate_alias_key
RSpec.deprecate("add_setting with :alias option", :replacement => ":alias_with")
end
# @private
def self.define_aliases(name, alias_name)
alias_method alias_name, name
alias_method "#{alias_name}=", "#{name}="
define_predicate_for alias_name
end
# @private
def self.define_predicate_for(*names)
names.each {|name| alias_method "#{name}?", name}
end
# @private
#
# Invoked by the `add_setting` instance method. Use that method on a
# `Configuration` instance rather than this class method.
def self.add_setting(name, opts={})
raise "Use the instance add_setting method if you want to set a default" if opts.has_key?(:default)
if opts[:alias]
deprecate_alias_key
define_aliases(opts[:alias], name)
else
attr_writer name
define_reader name
define_predicate_for name
end
[opts[:alias_with]].flatten.compact.each do |alias_name|
define_aliases(name, alias_name)
end
end
# @macro [attach] add_setting
# @attribute $1
# Path to use if no path is provided to the `rspec` command (default:
# `"spec"`). Allows you to just type `rspec` instead of `rspec spec` to
# run all the examples in the `spec` directory.
add_setting :default_path
# Run examples over DRb (default: `false`). RSpec doesn't supply the DRb
# server, but you can use tools like spork.
add_setting :drb
# The drb_port (default: nil).
add_setting :drb_port
# Default: `$stderr`.
add_setting :error_stream
# Default: `$stderr`.
add_setting :deprecation_stream
# Clean up and exit after the first failure (default: `false`).
add_setting :fail_fast
# The exit code to return if there are any failures (default: 1).
add_setting :failure_exit_code
# Determines the order in which examples are run (default: OS standard
# load order for files, declaration order for groups and examples).
define_reader :order
# Indicates files configured to be required
define_reader :requires
# Returns dirs that have been prepended to the load path by #lib=
define_reader :libs
# Default: `$stdout`.
# Also known as `output` and `out`
add_setting :output_stream, :alias_with => [:output, :out]
# Load files matching this pattern (default: `'**/*_spec.rb'`)
add_setting :pattern, :alias_with => :filename_pattern
# Report the times for the slowest examples (default: `false`).
# Use this to specify the number of examples to include in the profile.
add_setting :profile_examples
# Run all examples if none match the configured filters (default: `false`).
add_setting :run_all_when_everything_filtered
# Allow user to configure their own success/pending/failure colors
# @param [Symbol] should be one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
add_setting :success_color
add_setting :pending_color
add_setting :failure_color
add_setting :default_color
add_setting :fixed_color
add_setting :detail_color
# Seed for random ordering (default: generated randomly each run).
#
# When you run specs with `--order random`, RSpec generates a random seed
# for the randomization and prints it to the `output_stream` (assuming
# you're using RSpec's built-in formatters). If you discover an ordering
# dependency (i.e. examples fail intermittently depending on order), set
# this (on Configuration or on the command line with `--seed`) to run
# using the same seed while you debug the issue.
#
# We recommend, actually, that you use the command line approach so you
# don't accidentally leave the seed encoded.
define_reader :seed
# When a block passed to pending fails (as expected), display the failure
# without reporting it as a failure (default: false).
add_setting :show_failures_in_pending_blocks
# Convert symbols to hashes with the symbol as a key with a value of
# `true` (default: false).
#
# This allows you to tag a group or example like this:
#
# describe "something slow", :slow do
# # ...
# end
#
# ... instead of having to type:
#
# describe "something slow", :slow => true do
# # ...
# end
add_setting :treat_symbols_as_metadata_keys_with_true_values
# @private
add_setting :tty
# @private
add_setting :include_or_extend_modules
# @private
add_setting :files_to_run
# @private
add_setting :expecting_with_rspec
# @private
attr_accessor :filter_manager
attr_reader :backtrace_cleaner
def initialize
@expectation_frameworks = []
@include_or_extend_modules = []
@mock_framework = nil
@files_to_run = []
@formatters = []
@color = false
@pattern = '**/*_spec.rb'
@failure_exit_code = 1
@backtrace_cleaner = BacktraceCleaner.new
@default_path = 'spec'
@deprecation_stream = $stderr
@filter_manager = FilterManager.new
@preferred_options = {}
@seed = srand % 0xFFFF
@failure_color = :red
@success_color = :green
@pending_color = :yellow
@default_color = :white
@fixed_color = :blue
@detail_color = :cyan
@profile_examples = false
@requires = []
@libs = []
end
# @private
#
# Used to set higher priority option values from the command line.
def force(hash)
if hash.has_key?(:seed)
hash[:order], hash[:seed] = order_and_seed_from_seed(hash[:seed])
elsif hash.has_key?(:order)
set_order_and_seed(hash)
end
@preferred_options.merge!(hash)
self.warnings = value_for :warnings, nil
end
# @private
def reset
@reporter = nil
@formatters.clear
end
# @overload add_setting(name)
# @overload add_setting(name, opts)
# @option opts [Symbol] :default
#
# set a default value for the generated getter and predicate methods:
#
# add_setting(:foo, :default => "default value")
#
# @option opts [Symbol] :alias_with
#
# Use `:alias_with` to alias the setter, getter, and predicate to another
# name, or names:
#
# add_setting(:foo, :alias_with => :bar)
# add_setting(:foo, :alias_with => [:bar, :baz])
#
# Adds a custom setting to the RSpec.configuration object.
#
# RSpec.configuration.add_setting :foo
#
# Used internally and by extension frameworks like rspec-rails, so they
# can add config settings that are domain specific. For example:
#
# RSpec.configure do |c|
# c.add_setting :use_transactional_fixtures,
# :default => true,
# :alias_with => :use_transactional_examples
# end
#
# `add_setting` creates three methods on the configuration object, a
# setter, a getter, and a predicate:
#
# RSpec.configuration.foo=(value)
# RSpec.configuration.foo
# RSpec.configuration.foo? # returns true if foo returns anything but nil or false
def add_setting(name, opts={})
default = opts.delete(:default)
(class << self; self; end).class_eval do
add_setting(name, opts)
end
send("#{name}=", default) if default
end
# Returns the configured mock framework adapter module
def mock_framework
mock_with :rspec unless @mock_framework
@mock_framework
end
# Delegates to mock_framework=(framework)
def mock_framework=(framework)
mock_with framework
end
# The patterns to discard from backtraces. Deprecated, use
# Configuration#backtrace_exclusion_patterns instead
#
# Defaults to RSpec::Core::BacktraceCleaner::DEFAULT_EXCLUSION_PATTERNS
#
# One can replace the list by using the setter or modify it through the
# getter
#
# To override this behaviour and display a full backtrace, use
# `--backtrace`on the command line, in a `.rspec` file, or in the
# `rspec_options` attribute of RSpec's rake task.
def backtrace_clean_patterns
RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
:replacement => "RSpec::Core::Configuration#backtrace_exclusion_patterns")
@backtrace_cleaner.exclusion_patterns
end
def backtrace_clean_patterns=(patterns)
RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
:replacement => "RSpec::Core::Configuration#backtrace_exclusion_patterns")
@backtrace_cleaner.exclusion_patterns = patterns
end
# The patterns to always include to backtraces.
#
# Defaults to [Regexp.new Dir.getwd] if the current working directory
# matches any of the exclusion patterns. Otherwise it defaults to empty.
#
# One can replace the list by using the setter or modify it through the
# getter
def backtrace_inclusion_patterns
@backtrace_cleaner.inclusion_patterns
end
def backtrace_inclusion_patterns=(patterns)
@backtrace_cleaner.inclusion_patterns = patterns
end
# The patterns to discard from backtraces.
#
# Defaults to RSpec::Core::BacktraceCleaner::DEFAULT_EXCLUSION_PATTERNS
#
# One can replace the list by using the setter or modify it through the
# getter
#
# To override this behaviour and display a full backtrace, use
# `--backtrace`on the command line, in a `.rspec` file, or in the
# `rspec_options` attribute of RSpec's rake task.
def backtrace_exclusion_patterns
@backtrace_cleaner.exclusion_patterns
end
def backtrace_exclusion_patterns=(patterns)
@backtrace_cleaner.exclusion_patterns = patterns
end
# Sets the mock framework adapter module.
#
# `framework` can be a Symbol or a Module.
#
# Given any of `:rspec`, `:mocha`, `:flexmock`, or `:rr`, configures the
# named framework.
#
# Given `:nothing`, configures no framework. Use this if you don't use
# any mocking framework to save a little bit of overhead.
#
# Given a Module, includes that module in every example group. The module
# should adhere to RSpec's mock framework adapter API:
#
# setup_mocks_for_rspec
# - called before each example
#
# verify_mocks_for_rspec
# - called after each example. Framework should raise an exception
# when expectations fail
#
# teardown_mocks_for_rspec
# - called after verify_mocks_for_rspec (even if there are errors)
#
# If the module responds to `configuration` and `mock_with` receives a block,
# it will yield the configuration object to the block e.g.
#
# config.mock_with OtherMockFrameworkAdapter do |mod_config|
# mod_config.custom_setting = true
# end
def mock_with(framework)
framework_module = case framework
when Module
framework
when String, Symbol
require case framework.to_s
when /rspec/i
'rspec/core/mocking/with_rspec'
when /mocha/i
'rspec/core/mocking/with_mocha'
when /rr/i
'rspec/core/mocking/with_rr'
when /flexmock/i
'rspec/core/mocking/with_flexmock'
else
'rspec/core/mocking/with_absolutely_nothing'
end
RSpec::Core::MockFrameworkAdapter
end
new_name, old_name = [framework_module, @mock_framework].map do |mod|
mod.respond_to?(:framework_name) ? mod.framework_name : :unnamed
end
unless new_name == old_name
assert_no_example_groups_defined(:mock_framework)
end
if block_given?
raise "#{framework_module} must respond to `configuration` so that mock_with can yield it." unless framework_module.respond_to?(:configuration)
yield framework_module.configuration
end
@mock_framework = framework_module
end
# Returns the configured expectation framework adapter module(s)
def expectation_frameworks
expect_with :rspec if @expectation_frameworks.empty?
@expectation_frameworks
end
# Delegates to expect_with(framework)
def expectation_framework=(framework)
expect_with(framework)
end
# Sets the expectation framework module(s) to be included in each example
# group.
#
# `frameworks` can be `:rspec`, `:stdlib`, a custom module, or any
# combination thereof:
#
# config.expect_with :rspec
# config.expect_with :stdlib
# config.expect_with :rspec, :stdlib
# config.expect_with OtherExpectationFramework
#
# RSpec will translate `:rspec` and `:stdlib` into the appropriate
# modules.
#
# ## Configuration
#
# If the module responds to `configuration`, `expect_with` will
# yield the `configuration` object if given a block:
#
# config.expect_with OtherExpectationFramework do |custom_config|
# custom_config.custom_setting = true
# end
def expect_with(*frameworks)
modules = frameworks.map do |framework|
case framework
when Module
framework
when :rspec
require 'rspec/expectations'
self.expecting_with_rspec = true
::RSpec::Matchers
when :stdlib
require 'test/unit/assertions'
::Test::Unit::Assertions
else
raise ArgumentError, "#{framework.inspect} is not supported"
end
end
if (modules - @expectation_frameworks).any?
assert_no_example_groups_defined(:expect_with)
end
if block_given?
raise "expect_with only accepts a block with a single argument. Call expect_with #{modules.length} times, once with each argument, instead." if modules.length > 1
raise "#{modules.first} must respond to `configuration` so that expect_with can yield it." unless modules.first.respond_to?(:configuration)
yield modules.first.configuration
end
@expectation_frameworks.push(*modules)
end
def full_backtrace?
@backtrace_cleaner.full_backtrace?
end
def full_backtrace=(true_or_false)
@backtrace_cleaner.full_backtrace = true_or_false
end
def color(output=output_stream)
# rspec's built-in formatters all call this with the output argument,
# but defaulting to output_stream for backward compatibility with
# formatters in extension libs
return false unless output_to_tty?(output)
value_for(:color, @color)
end
def color=(bool)
if bool
if RSpec.windows_os? and not ENV['ANSICON']
warn "You must use ANSICON 1.31 or later (http://adoxa.3eeweb.com/ansicon/) to use colour on Windows"
@color = false
else
@color = true
end
end
end
# TODO - deprecate color_enabled - probably not until the last 2.x
# release before 3.0
alias_method :color_enabled, :color
alias_method :color_enabled=, :color=
define_predicate_for :color_enabled, :color
def libs=(libs)
libs.map do |lib|
@libs.unshift lib
$LOAD_PATH.unshift lib
end
end
def requires=(paths)
RSpec.deprecate("RSpec::Core::Configuration#requires=(paths)",
:replacement => "paths.each {|path| require path}")
paths.map {|path| require path}
@requires += paths
end
def debug=(bool)
return unless bool
begin
require 'ruby-debug'
Debugger.start
rescue LoadError => e
raise <<-EOM
#{'*'*50}
#{e.message}
If you have it installed as a ruby gem, then you need to either require
'rubygems' or configure the RUBYOPT environment variable with the value
'rubygems'.
#{e.backtrace.join("\n")}
#{'*'*50}
EOM
end
end
def debug?
!!defined?(Debugger)
end
# Run examples defined on `line_numbers` in all files to run.
def line_numbers=(line_numbers)
filter_run :line_numbers => line_numbers.map{|l| l.to_i}
end
def line_numbers
filter.fetch(:line_numbers,[])
end
def full_description=(description)
filter_run :full_description => Regexp.union(*Array(description).map {|d| Regexp.new(d) })
end
def full_description
filter.fetch :full_description, nil
end
# @overload add_formatter(formatter)
#
# Adds a formatter to the formatters collection. `formatter` can be a
# string representing any of the built-in formatters (see
# `built_in_formatter`), or a custom formatter class.
#
# ### Note
#
# For internal purposes, `add_formatter` also accepts the name of a class
# and paths to use for output streams, but you should consider that a
# private api that may change at any time without notice.
def add_formatter(formatter_to_use, *paths)
formatter_class =
built_in_formatter(formatter_to_use) ||
custom_formatter(formatter_to_use) ||
(raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.")
paths << output if paths.empty?
formatters << formatter_class.new(*paths.map {|p| String === p ? file_at(p) : p})
end
alias_method :formatter=, :add_formatter
def formatters
@formatters ||= []
end
def reporter
@reporter ||= begin
add_formatter('progress') if formatters.empty?
add_formatter(RSpec::Core::Formatters::DeprecationFormatter, deprecation_stream, output_stream)
Reporter.new(*formatters)
end
end
# @api private
#
# Defaults `profile_examples` to 10 examples when `@profile_examples` is `true`.
#
def profile_examples
profile = value_for(:profile_examples, @profile_examples)
if profile && !profile.is_a?(Integer)
10
else
profile
end
end
# @private
def files_or_directories_to_run=(*files)
files = files.flatten
files << default_path if (command == 'rspec' || Runner.running_in_drb?) && default_path && files.empty?
self.files_to_run = get_files_to_run(files)
end
# Creates a method that delegates to `example` including the submitted
# `args`. Used internally to add variants of `example` like `pending`:
#
# @example
# alias_example_to :pending, :pending => true
#
# # This lets you do this:
#
# describe Thing do
# pending "does something" do
# thing = Thing.new
# end
# end
#
# # ... which is the equivalent of
#
# describe Thing do
# it "does something", :pending => true do
# thing = Thing.new
# end
# end
def alias_example_to(new_name, *args)
extra_options = build_metadata_hash_from(args)
RSpec::Core::ExampleGroup.alias_example_to(new_name, extra_options)
end
# Define an alias for it_should_behave_like that allows different
# language (like "it_has_behavior" or "it_behaves_like") to be
# employed when including shared examples.
#
# Example:
#
# alias_it_behaves_like_to(:it_has_behavior, 'has behavior:')
#
# allows the user to include a shared example group like:
#
# describe Entity do
# it_has_behavior 'sortability' do
# let(:sortable) { Entity.new }
# end
# end
#
# which is reported in the output as:
#
# Entity
# has behavior: sortability
# # sortability examples here
def alias_it_behaves_like_to(new_name, report_label = '')
RSpec::Core::ExampleGroup.alias_it_behaves_like_to(new_name, report_label)
end
alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to
# Adds key/value pairs to the `inclusion_filter`. If the
# `treat_symbols_as_metadata_keys_with_true_values` config option is set
# to true and `args` includes any symbols that are not part of a hash,
# each symbol is treated as a key in the hash with the value `true`.
#
# ### Note
#
# Filters set using this method can be overridden from the command line
# or config files (e.g. `.rspec`).
#
# @example
# # given this declaration
# describe "something", :foo => 'bar' do
# # ...
# end
#
# # any of the following will include that group
# config.filter_run_including :foo => 'bar'
# config.filter_run_including :foo => /^ba/
# config.filter_run_including :foo => lambda {|v| v == 'bar'}
# config.filter_run_including :foo => lambda {|v,m| m[:foo] == 'bar'}
#
# # given a proc with an arity of 1, the lambda is passed the value related to the key, e.g.
# config.filter_run_including :foo => lambda {|v| v == 'bar'}
#
# # given a proc with an arity of 2, the lambda is passed the value related to the key,
# # and the metadata itself e.g.
# config.filter_run_including :foo => lambda {|v,m| m[:foo] == 'bar'}
#
# # with treat_symbols_as_metadata_keys_with_true_values = true
# filter_run_including :foo # same as filter_run_including :foo => true
def filter_run_including(*args)
filter_manager.include_with_low_priority build_metadata_hash_from(args)
end
alias_method :filter_run, :filter_run_including
# Clears and reassigns the `inclusion_filter`. Set to `nil` if you don't
# want any inclusion filter at all.
#
# ### Warning
#
# This overrides any inclusion filters/tags set on the command line or in
# configuration files.
def inclusion_filter=(filter)
filter_manager.include! build_metadata_hash_from([filter])
end
alias_method :filter=, :inclusion_filter=
# Returns the `inclusion_filter`. If none has been set, returns an empty
# hash.
def inclusion_filter
filter_manager.inclusions
end
alias_method :filter, :inclusion_filter
# Adds key/value pairs to the `exclusion_filter`. If the
# `treat_symbols_as_metadata_keys_with_true_values` config option is set
# to true and `args` excludes any symbols that are not part of a hash,
# each symbol is treated as a key in the hash with the value `true`.
#
# ### Note
#
# Filters set using this method can be overridden from the command line
# or config files (e.g. `.rspec`).
#
# @example
# # given this declaration
# describe "something", :foo => 'bar' do
# # ...
# end
#
# # any of the following will exclude that group
# config.filter_run_excluding :foo => 'bar'
# config.filter_run_excluding :foo => /^ba/
# config.filter_run_excluding :foo => lambda {|v| v == 'bar'}
# config.filter_run_excluding :foo => lambda {|v,m| m[:foo] == 'bar'}
#
# # given a proc with an arity of 1, the lambda is passed the value related to the key, e.g.
# config.filter_run_excluding :foo => lambda {|v| v == 'bar'}
#
# # given a proc with an arity of 2, the lambda is passed the value related to the key,
# # and the metadata itself e.g.
# config.filter_run_excluding :foo => lambda {|v,m| m[:foo] == 'bar'}
#
# # with treat_symbols_as_metadata_keys_with_true_values = true
# filter_run_excluding :foo # same as filter_run_excluding :foo => true
def filter_run_excluding(*args)
filter_manager.exclude_with_low_priority build_metadata_hash_from(args)
end
# Clears and reassigns the `exclusion_filter`. Set to `nil` if you don't
# want any exclusion filter at all.
#
# ### Warning
#
# This overrides any exclusion filters/tags set on the command line or in
# configuration files.
def exclusion_filter=(filter)
filter_manager.exclude! build_metadata_hash_from([filter])
end
# Returns the `exclusion_filter`. If none has been set, returns an empty
# hash.
def exclusion_filter
filter_manager.exclusions
end
# Tells RSpec to include `mod` in example groups. Methods defined in
# `mod` are exposed to examples (not example groups). Use `filters` to
# constrain the groups in which to include the module.
#
# @example
#
# module AuthenticationHelpers
# def login_as(user)
# # ...
# end
# end
#
# module UserHelpers
# def users(username)
# # ...
# end
# end
#
# RSpec.configure do |config|
# config.include(UserHelpers) # included in all modules
# config.include(AuthenticationHelpers, :type => :request)
# end
#
# describe "edit profile", :type => :request do
# it "can be viewed by owning user" do
# login_as users(:jdoe)
# get "/profiles/jdoe"
# assert_select ".username", :text => 'jdoe'
# end
# end
#
# @see #extend
def include(mod, *filters)
include_or_extend_modules << [:include, mod, build_metadata_hash_from(filters)]
end
# Tells RSpec to extend example groups with `mod`. Methods defined in
# `mod` are exposed to example groups (not examples). Use `filters` to
# constrain the groups to extend.
#
# Similar to `include`, but behavior is added to example groups, which
# are classes, rather than the examples, which are instances of those
# classes.
#
# @example
#
# module UiHelpers
# def run_in_browser
# # ...
# end
# end
#
# RSpec.configure do |config|
# config.extend(UiHelpers, :type => :request)
# end
#
# describe "edit profile", :type => :request do
# run_in_browser
#
# it "does stuff in the client" do
# # ...
# end
# end
#
# @see #include
def extend(mod, *filters)
include_or_extend_modules << [:extend, mod, build_metadata_hash_from(filters)]
end
# @private
#
# Used internally to extend a group with modules using `include` and/or
# `extend`.
def configure_group(group)
include_or_extend_modules.each do |include_or_extend, mod, filters|
next unless filters.empty? || group.any_apply?(filters)
send("safe_#{include_or_extend}", mod, group)
end
end
# @private
def safe_include(mod, host)
host.send(:include,mod) unless host < mod
end
# @private
def setup_load_path_and_require(paths)
directories = ['lib', default_path].select { |p| File.directory? p }
RSpec::Core::RubyProject.add_to_load_path(*directories)
paths.each {|path| require path}
@requires += paths
end
# @private
if RUBY_VERSION.to_f >= 1.9
def safe_extend(mod, host)
host.extend(mod) unless (class << host; self; end) < mod
end
else
def safe_extend(mod, host)
host.extend(mod) unless (class << host; self; end).included_modules.include?(mod)
end
end
# @private
def configure_mock_framework
RSpec::Core::ExampleGroup.send(:include, mock_framework)
end
# @private
def configure_expectation_framework
expectation_frameworks.each do |framework|
RSpec::Core::ExampleGroup.send(:include, framework)
end
end
# @private
def load_spec_files
files_to_run.uniq.each {|f| load File.expand_path(f) }
raise_if_rspec_1_is_loaded
end
# @private
DEFAULT_FORMATTER = lambda { |string| string }
# Formats the docstring output using the block provided.
#
# @example
# # This will strip the descriptions of both examples and example groups.
# RSpec.configure do |config|
# config.format_docstrings { |s| s.strip }
# end
def format_docstrings(&block)
@format_docstrings_block = block_given? ? block : DEFAULT_FORMATTER
end
# @private
def format_docstrings_block
@format_docstrings_block ||= DEFAULT_FORMATTER
end
# @api
#
# Sets the seed value and sets `order='rand'`
def seed=(seed)
order_and_seed_from_seed(seed)
end
# @api
#
# Sets the order and, if order is `'rand:'`, also sets the seed.
def order=(type)
order_and_seed_from_order(type)
end
def randomize?
order.to_s.match(/rand/)
end
# @private
DEFAULT_ORDERING = lambda { |list| list }
# @private
RANDOM_ORDERING = lambda do |list|
Kernel.srand RSpec.configuration.seed
ordering = list.sort_by { Kernel.rand(list.size) }
Kernel.srand # reset random generation
ordering
end
# Sets a strategy by which to order examples.
#
# @example
# RSpec.configure do |config|
# config.order_examples do |examples|
# examples.reverse
# end
# end
#
# @see #order_groups
# @see #order_groups_and_examples
# @see #order=
# @see #seed=
def order_examples(&block)
@example_ordering_block = block
@order = "custom" unless built_in_orderer?(block)
end
# @private
def example_ordering_block
@example_ordering_block ||= DEFAULT_ORDERING
end
# Sets a strategy by which to order groups.
#
# @example
# RSpec.configure do |config|
# config.order_groups do |groups|
# groups.reverse
# end
# end
#
# @see #order_examples
# @see #order_groups_and_examples
# @see #order=
# @see #seed=
def order_groups(&block)
@group_ordering_block = block
@order = "custom" unless built_in_orderer?(block)
end
# @private
def group_ordering_block
@group_ordering_block ||= DEFAULT_ORDERING
end
# Sets a strategy by which to order groups and examples.
#
# @example
# RSpec.configure do |config|
# config.order_groups_and_examples do |groups_or_examples|
# groups_or_examples.reverse
# end
# end
#
# @see #order_groups
# @see #order_examples
# @see #order=
# @see #seed=
def order_groups_and_examples(&block)
order_groups(&block)
order_examples(&block)
end
# Set Ruby warnings on or off
def warnings= value
$VERBOSE = !!value
end
def warnings
$VERBOSE
end
private
def get_files_to_run(paths)
paths.map do |path|
path = path.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
File.directory?(path) ? gather_directories(path) : extract_location(path)
end.flatten.sort
end
def gather_directories(path)
stripped = "{#{pattern.gsub(/\s*,\s*/, ',')}}"
files = pattern =~ /^#{Regexp.escape path}/ ? Dir[stripped] : Dir["#{path}/#{stripped}"]
files.sort
end
def extract_location(path)
if path =~ /^(.*?)((?:\:\d+)+)$/
path, lines = $1, $2[1..-1].split(":").map{|n| n.to_i}
filter_manager.add_location path, lines
end
path
end
def command
$0.split(File::SEPARATOR).last
end
def value_for(key, default=nil)
@preferred_options.has_key?(key) ? @preferred_options[key] : default
end
def assert_no_example_groups_defined(config_option)
if RSpec.world.example_groups.any?
raise MustBeConfiguredBeforeExampleGroupsError.new(
"RSpec's #{config_option} configuration option must be configured before " +
"any example groups are defined, but you have already defined a group."
)
end
end
def raise_if_rspec_1_is_loaded
if defined?(Spec) && defined?(Spec::VERSION::MAJOR) && Spec::VERSION::MAJOR == 1
raise <<-MESSAGE
#{'*'*80}
You are running rspec-2, but it seems as though rspec-1 has been loaded as
well. This is likely due to a statement like this somewhere in the specs:
require 'spec'
Please locate that statement, remove it, and try again.
#{'*'*80}
MESSAGE
end
end
def output_to_tty?(output=output_stream)
tty? || (output.respond_to?(:tty?) && output.tty?)
end
def built_in_formatter(key)
case key.to_s
when 'd', 'doc', 'documentation', 's', 'n', 'spec', 'nested'
require 'rspec/core/formatters/documentation_formatter'
RSpec::Core::Formatters::DocumentationFormatter
when 'h', 'html'
require 'rspec/core/formatters/html_formatter'
RSpec::Core::Formatters::HtmlFormatter
when 't', 'textmate'
require 'rspec/core/formatters/text_mate_formatter'
RSpec::Core::Formatters::TextMateFormatter
when 'p', 'progress'
require 'rspec/core/formatters/progress_formatter'
RSpec::Core::Formatters::ProgressFormatter
when 'j', 'json'
require 'rspec/core/formatters/json_formatter'
RSpec::Core::Formatters::JsonFormatter
end
end
def custom_formatter(formatter_ref)
if Class === formatter_ref
formatter_ref
elsif string_const?(formatter_ref)
begin
eval(formatter_ref)
rescue NameError
require path_for(formatter_ref)
eval(formatter_ref)
end
end
end
def string_const?(str)
str.is_a?(String) && /\A[A-Z][a-zA-Z0-9_:]*\z/ =~ str
end
def path_for(const_ref)
underscore_with_fix_for_non_standard_rspec_naming(const_ref)
end
def underscore_with_fix_for_non_standard_rspec_naming(string)
underscore(string).sub(%r{(^|/)r_spec($|/)}, '\\1rspec\\2')
end
# activesupport/lib/active_support/inflector/methods.rb, line 48
def underscore(camel_cased_word)
word = camel_cased_word.to_s.dup
word.gsub!(/::/, '/')
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
word.tr!("-", "_")
word.downcase!
word
end
def file_at(path)
FileUtils.mkdir_p(File.dirname(path))
File.new(path, 'w')
end
def order_and_seed_from_seed(value)
order_groups_and_examples(&RANDOM_ORDERING)
@order, @seed = 'rand', value.to_i
[@order, @seed]
end
def set_order_and_seed(hash)
hash[:order], seed = order_and_seed_from_order(hash[:order])
hash[:seed] = seed if seed
end
def order_and_seed_from_order(type)
order, seed = type.to_s.split(':')
@order = order
@seed = seed = seed.to_i if seed
if randomize?
order_groups_and_examples(&RANDOM_ORDERING)
elsif order == 'default'
@order, @seed = nil, nil
order_groups_and_examples(&DEFAULT_ORDERING)
end
return order, seed
end
def built_in_orderer?(block)
[DEFAULT_ORDERING, RANDOM_ORDERING].include?(block)
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/metadata_hash_builder.rb 0000644 0000041 0000041 00000005074 12261207027 023334 0 ustar www-data www-data module RSpec
module Core
# @private
module MetadataHashBuilder
# @private
module Common
def build_metadata_hash_from(args)
metadata = args.last.is_a?(Hash) ? args.pop : {}
if RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values?
add_symbols_to_hash(metadata, args)
else
warn_about_symbol_usage(args)
end
metadata
end
private
def add_symbols_to_hash(hash, args)
while args.last.is_a?(Symbol)
hash[args.pop] = true
end
end
def warn_about_symbol_usage(args)
symbols = args.select { |a| a.is_a?(Symbol) }
return if symbols.empty?
Kernel.warn symbol_metadata_warning(symbols)
end
end
# @private
module WithConfigWarning
include Common
private
def symbol_metadata_warning(symbols)
<<-NOTICE
*****************************************************************
WARNING: You have passed symbols (#{symbols.inspect}) as metadata
arguments to a configuration option.
In RSpec 3, these symbols will be treated as metadata keys with
a value of `true`. To get this behavior now (and prevent this
warning), you can set a configuration option:
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
end
Note that this config setting should go before your other config
settings so that they can use symbols as metadata.
*****************************************************************
NOTICE
end
end
# @private
module WithDeprecationWarning
include Common
private
def symbol_metadata_warning(symbols)
<<-NOTICE
*****************************************************************
DEPRECATION WARNING: you are using deprecated behaviour that will
be removed from RSpec 3.
You have passed symbols (#{symbols.inspect}) as additional
arguments for a doc string.
In RSpec 3, these symbols will be treated as metadata keys with
a value of `true`. To get this behavior now (and prevent this
warning), you can set a configuration option:
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
end
Alternately, if your intention is to use the symbol as part of the
doc string (i.e. to specify a method name), you can change it to
a string such as "#method_name" to remove this warning.
*****************************************************************
NOTICE
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/example.rb 0000644 0000041 0000041 00000024323 12261207027 020474 0 ustar www-data www-data module RSpec
module Core
# Wrapper for an instance of a subclass of {ExampleGroup}. An instance of
# `Example` is returned by the {ExampleGroup#example example} method
# exposed to examples, {Hooks#before before} and {Hooks#after after} hooks,
# and yielded to {Hooks#around around} hooks.
#
# Useful for configuring logging and/or taking some action based
# on the state of an example's metadata.
#
# @example
#
# RSpec.configure do |config|
# config.before do
# log example.description
# end
#
# config.after do
# log example.description
# end
#
# config.around do |ex|
# log example.description
# ex.run
# end
# end
#
# shared_examples "auditable" do
# it "does something" do
# log "#{example.full_description}: #{auditable.inspect}"
# auditable.should do_something
# end
# end
#
# @see ExampleGroup
class Example
# @private
#
# Used to define methods that delegate to this example's metadata
def self.delegate_to_metadata(*keys)
keys.each { |key| define_method(key) { @metadata[key] } }
end
delegate_to_metadata :full_description, :execution_result, :file_path, :pending, :location
# Returns the string submitted to `example` or its aliases (e.g.
# `specify`, `it`, etc). If no string is submitted (e.g. `it { should
# do_something }`) it returns the message generated by the matcher if
# there is one, otherwise returns a message including the location of the
# example.
def description
description = metadata[:description].to_s.empty? ? "example at #{location}" : metadata[:description]
RSpec.configuration.format_docstrings_block.call(description)
end
# @attr_reader
#
# Returns the first exception raised in the context of running this
# example (nil if no exception is raised)
attr_reader :exception
# @attr_reader
#
# Returns the metadata object associated with this example.
attr_reader :metadata
# @attr_reader
# @private
#
# Returns the example_group_instance that provides the context for
# running this example.
attr_reader :example_group_instance
# Creates a new instance of Example.
# @param example_group_class the subclass of ExampleGroup in which this Example is declared
# @param description the String passed to the `it` method (or alias)
# @param metadata additional args passed to `it` to be used as metadata
# @param example_block the block of code that represents the example
def initialize(example_group_class, description, metadata, example_block=nil)
@example_group_class, @options, @example_block = example_group_class, metadata, example_block
@metadata = @example_group_class.metadata.for_example(description, metadata)
@example_group_instance = @exception = nil
@pending_declared_in_example = false
end
# @deprecated access options via metadata instead
def options
@options
end
# Returns the example group class that provides the context for running
# this example.
def example_group
@example_group_class
end
alias_method :pending?, :pending
# @api private
# instance_evals the block passed to the constructor in the context of
# the instance of {ExampleGroup}.
# @param example_group_instance the instance of an ExampleGroup subclass
def run(example_group_instance, reporter)
@example_group_instance = example_group_instance
@example_group_instance.example = self
start(reporter)
begin
unless pending
with_around_each_hooks do
begin
run_before_each
@example_group_instance.instance_eval(&@example_block)
rescue Pending::PendingDeclaredInExample => e
@pending_declared_in_example = e.message
rescue Exception => e
set_exception(e)
ensure
run_after_each
end
end
end
rescue Exception => e
set_exception(e)
ensure
@example_group_instance.instance_variables.each do |ivar|
@example_group_instance.instance_variable_set(ivar, nil)
end
@example_group_instance = nil
begin
assign_generated_description
rescue Exception => e
set_exception(e, "while assigning the example description")
end
end
finish(reporter)
end
# @api private
#
# Wraps the example block in a Proc so it can invoked using `run` or
# `call` in [around](../Hooks#around-instance_method) hooks.
def self.procsy(metadata, &proc)
proc.extend(Procsy).with(metadata)
end
# Used to extend a `Proc` with behavior that makes it look something like
# an {Example} in an {Hooks#around around} hook.
#
# @note Procsy, itself, is not a public API, but we're documenting it
# here to document how to interact with the object yielded to an
# `around` hook.
#
# @example
#
# RSpec.configure do |c|
# c.around do |ex| # ex is a Proc extended with Procsy
# if ex.metadata[:key] == :some_value && some_global_condition
# raise "some message"
# end
# ex.run # run delegates to ex.call
# end
# end
module Procsy
# The `metadata` of the {Example} instance.
attr_reader :metadata
# @api private
# @param [Proc]
# Adds a `run` method to the extended Proc, allowing it to be invoked
# in an [around](../Hooks#around-instance_method) hook using either
# `run` or `call`.
def self.extended(proc)
# @api public
# Foo bar
def proc.run; call; end
end
# @api private
def with(metadata)
@metadata = metadata
self
end
end
# @private
def any_apply?(filters)
metadata.any_apply?(filters)
end
# @private
def all_apply?(filters)
@metadata.all_apply?(filters) || @example_group_class.all_apply?(filters)
end
# @private
def around_each_hooks
@around_each_hooks ||= example_group.around_each_hooks_for(self)
end
# @private
#
# Used internally to set an exception in an after hook, which
# captures the exception but doesn't raise it.
def set_exception(exception, context=nil)
if @exception && context != :dont_print
# An error has already been set; we don't want to override it,
# but we also don't want silence the error, so let's print it.
msg = <<-EOS
An error occurred #{context}
#{exception.class}: #{exception.message}
occurred at #{exception.backtrace.first}
EOS
RSpec.configuration.reporter.message(msg)
end
@exception ||= exception
end
# @private
#
# Used internally to set an exception and fail without actually executing
# the example when an exception is raised in before(:all).
def fail_with_exception(reporter, exception)
start(reporter)
set_exception(exception)
finish(reporter)
end
# @private
def instance_eval(*args, &block)
@example_group_instance.instance_eval(*args, &block)
end
# @private
def instance_eval_with_rescue(context = nil, &block)
@example_group_instance.instance_eval_with_rescue(context, &block)
end
# @private
def instance_eval_with_args(*args, &block)
@example_group_instance.instance_eval_with_args(*args, &block)
end
private
def with_around_each_hooks(&block)
if around_each_hooks.empty?
yield
else
@example_group_class.run_around_each_hooks(self, Example.procsy(metadata, &block))
end
rescue Exception => e
set_exception(e, "in an around(:each) hook")
end
def start(reporter)
reporter.example_started(self)
record :started_at => RSpec::Core::Time.now
end
def finish(reporter)
if @exception
record_finished 'failed', :exception => @exception
reporter.example_failed self
false
elsif @pending_declared_in_example
record_finished 'pending', :pending_message => @pending_declared_in_example
reporter.example_pending self
true
elsif pending
record_finished 'pending', :pending_message => String === pending ? pending : Pending::NO_REASON_GIVEN
reporter.example_pending self
true
else
record_finished 'passed'
reporter.example_passed self
true
end
end
def record_finished(status, results={})
finished_at = RSpec::Core::Time.now
record results.merge(:status => status, :finished_at => finished_at, :run_time => (finished_at - execution_result[:started_at]).to_f)
end
def run_before_each
@example_group_instance.setup_mocks_for_rspec
@example_group_class.run_before_each_hooks(self)
end
def run_after_each
@example_group_class.run_after_each_hooks(self)
verify_mocks
rescue Exception => e
set_exception(e, "in an after(:each) hook")
ensure
@example_group_instance.teardown_mocks_for_rspec
end
def verify_mocks
@example_group_instance.verify_mocks_for_rspec
rescue Exception => e
set_exception(e, :dont_print)
end
def assign_generated_description
return unless RSpec.configuration.expecting_with_rspec?
if metadata[:description_args].empty? and !pending?
metadata[:description_args] << RSpec::Matchers.generated_description
end
RSpec::Matchers.clear_generated_description
end
def record(results={})
execution_result.update(results)
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/deprecation.rb 0000644 0000041 0000041 00000001740 12261207027 021334 0 ustar www-data www-data module RSpec
module Core
module Deprecation
# @private
#
# Used internally to print deprecation warnings
def deprecate(deprecated, replacement_or_hash={}, ignore_version=nil)
# Temporarily support old and new APIs while we transition the other
# rspec libs to use a hash for the 2nd arg and no version arg
data = Hash === replacement_or_hash ? replacement_or_hash : { :replacement => replacement_or_hash }
call_site = caller.find { |line| line !~ %r{/lib/rspec/(core|mocks|expectations|matchers|rails)/} }
RSpec.configuration.reporter.deprecation(
{
:deprecated => deprecated,
:call_site => call_site
}.merge(data)
)
end
# @private
#
# Used internally to print deprecation warnings
def warn_deprecation(message)
RSpec.configuration.reporter.deprecation :message => message
end
end
end
extend(Core::Deprecation)
end
rspec-core-2.14.7/lib/rspec/core/world.rb 0000644 0000041 0000041 00000007044 12261207027 020171 0 ustar www-data www-data module RSpec
module Core
class World
include RSpec::Core::Hooks
attr_reader :example_groups, :filtered_examples
attr_accessor :wants_to_quit
def initialize(configuration=RSpec.configuration)
@configuration = configuration
@example_groups = [].extend(Extensions::Ordered::ExampleGroups)
@filtered_examples = Hash.new { |hash,group|
hash[group] = begin
examples = group.examples.dup
examples = filter_manager.prune(examples)
examples.uniq
examples.extend(Extensions::Ordered::Examples)
end
}
end
def reset
example_groups.clear
SharedExampleGroup.registry.clear
end
def filter_manager
@configuration.filter_manager
end
def register(example_group)
example_groups << example_group
example_group
end
def inclusion_filter
@configuration.inclusion_filter
end
def exclusion_filter
@configuration.exclusion_filter
end
def configure_group(group)
@configuration.configure_group(group)
end
def example_count
example_groups.collect {|g| g.descendants}.flatten.inject(0) do |sum, g|
sum += g.filtered_examples.size
end
end
def preceding_declaration_line(filter_line)
declaration_line_numbers.sort.inject(nil) do |highest_prior_declaration_line, line|
line <= filter_line ? line : highest_prior_declaration_line
end
end
def reporter
@configuration.reporter
end
def announce_filters
filter_announcements = []
announce_inclusion_filter filter_announcements
announce_exclusion_filter filter_announcements
unless filter_manager.empty?
if filter_announcements.length == 1
reporter.message("Run options: #{filter_announcements[0]}")
else
reporter.message("Run options:\n #{filter_announcements.join("\n ")}")
end
end
if @configuration.run_all_when_everything_filtered? && example_count.zero?
reporter.message("#{everything_filtered_message}; ignoring #{inclusion_filter.description}")
filtered_examples.clear
inclusion_filter.clear
end
if example_count.zero?
example_groups.clear
if filter_manager.empty?
reporter.message("No examples found.")
elsif exclusion_filter.empty_without_conditional_filters?
message = everything_filtered_message
if @configuration.run_all_when_everything_filtered?
message << "; ignoring #{inclusion_filter.description}"
end
reporter.message(message)
elsif inclusion_filter.empty?
reporter.message(everything_filtered_message)
end
end
end
def everything_filtered_message
"\nAll examples were filtered out"
end
def announce_inclusion_filter(announcements)
unless inclusion_filter.empty?
announcements << "include #{inclusion_filter.description}"
end
end
def announce_exclusion_filter(announcements)
unless exclusion_filter.empty_without_conditional_filters?
announcements << "exclude #{exclusion_filter.description}"
end
end
private
def declaration_line_numbers
@line_numbers ||= example_groups.inject([]) do |lines, g|
lines + g.declaration_line_numbers
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/pending.rb 0000644 0000041 0000041 00000010043 12261207027 020457 0 ustar www-data www-data module RSpec
module Core
module Pending
class PendingDeclaredInExample < StandardError; end
# If Test::Unit is loaed, we'll use its error as baseclass, so that Test::Unit
# will report unmet RSpec expectations as failures rather than errors.
begin
class PendingExampleFixedError < Test::Unit::AssertionFailedError; end
rescue
class PendingExampleFixedError < StandardError; end
end
NO_REASON_GIVEN = 'No reason given'
NOT_YET_IMPLEMENTED = 'Not yet implemented'
# @overload pending()
# @overload pending(message)
# @overload pending(message, &block)
#
# Stops execution of an example, and reports it as pending. Takes an
# optional message and block.
#
# @param [String] message optional message to add to the summary report.
# @param [Block] block optional block. If it fails, the example is
# reported as pending. If it executes cleanly the example fails.
#
# @example
#
# describe "an example" do
# # reported as "Pending: no reason given"
# it "is pending with no message" do
# pending
# this_does_not_get_executed
# end
#
# # reported as "Pending: something else getting finished"
# it "is pending with a custom message" do
# pending("something else getting finished")
# this_does_not_get_executed
# end
#
# # reported as "Pending: something else getting finished"
# it "is pending with a failing block" do
# pending("something else getting finished") do
# raise "this is the failure"
# end
# end
#
# # reported as failure, saying we expected the block to fail but
# # it passed.
# it "is pending with a passing block" do
# pending("something else getting finished") do
# true.should be(true)
# end
# end
# end
#
# @note `before(:each)` hooks are eval'd when you use the `pending`
# method within an example. If you want to declare an example `pending`
# and bypass the `before` hooks as well, you can pass `:pending => true`
# to the `it` method:
#
# it "does something", :pending => true do
# # ...
# end
#
# or pass `:pending => "something else getting finished"` to add a
# message to the summary report:
#
# it "does something", :pending => "something else getting finished" do
# # ...
# end
def pending(*args)
return self.class.before(:each) { pending(*args) } unless example
options = args.last.is_a?(Hash) ? args.pop : {}
message = args.first || NO_REASON_GIVEN
if options[:unless] || (options.has_key?(:if) && !options[:if])
return block_given? ? yield : nil
end
example.metadata[:pending] = true
example.metadata[:execution_result][:pending_message] = message
example.execution_result[:pending_fixed] = false
if block_given?
begin
result = begin
yield
example.example_group_instance.instance_eval { verify_mocks_for_rspec }
true
end
example.metadata[:pending] = false
rescue Exception => e
example.execution_result[:exception] = e
ensure
teardown_mocks_for_rspec
end
if result
example.execution_result[:pending_fixed] = true
raise PendingExampleFixedError.new
end
end
raise PendingDeclaredInExample.new(message)
end
end
# Alias the error for compatibility with extension gems (e.g. formatters)
# that depend on the const name of the error in RSpec <= 2.8.
PendingExampleFixedError = Pending::PendingExampleFixedError
end
end
rspec-core-2.14.7/lib/rspec/core/metadata.rb 0000644 0000041 0000041 00000022555 12261207027 020626 0 ustar www-data www-data module RSpec
module Core
# Each ExampleGroup class and Example instance owns an instance of
# Metadata, which is Hash extended to support lazy evaluation of values
# associated with keys that may or may not be used by any example or group.
#
# In addition to metadata that is used internally, this also stores
# user-supplied metadata, e.g.
#
# describe Something, :type => :ui do
# it "does something", :slow => true do
# # ...
# end
# end
#
# `:type => :ui` is stored in the Metadata owned by the example group, and
# `:slow => true` is stored in the Metadata owned by the example. These can
# then be used to select which examples are run using the `--tag` option on
# the command line, or several methods on `Configuration` used to filter a
# run (e.g. `filter_run_including`, `filter_run_excluding`, etc).
#
# @see Example#metadata
# @see ExampleGroup.metadata
# @see FilterManager
# @see Configuration#filter_run_including
# @see Configuration#filter_run_excluding
class Metadata < Hash
def self.relative_path(line)
line = line.sub(File.expand_path("."), ".")
line = line.sub(/\A([^:]+:\d+)$/, '\\1')
return nil if line == '-e:1'
line
rescue SecurityError
nil
end
# @private
module MetadataHash
# @private
# Supports lazy evaluation of some values. Extended by
# ExampleMetadataHash and GroupMetadataHash, which get mixed in to
# Metadata for ExampleGroups and Examples (respectively).
def [](key)
store_computed(key) unless has_key?(key)
super
end
def fetch(key, *args)
store_computed(key) unless has_key?(key)
super
end
private
def store_computed(key)
case key
when :location
store(:location, location)
when :file_path, :line_number
file_path, line_number = file_and_line_number
store(:file_path, file_path)
store(:line_number, line_number)
when :execution_result
store(:execution_result, {})
when :describes, :described_class
klass = described_class
store(:described_class, klass)
# TODO (2011-11-07 DC) deprecate :describes as a key
store(:describes, klass)
when :full_description
store(:full_description, full_description)
when :description
store(:description, build_description_from(*self[:description_args]))
when :description_args
store(:description_args, [])
end
end
def location
"#{self[:file_path]}:#{self[:line_number]}"
end
def file_and_line_number
first_caller_from_outside_rspec =~ /(.+?):(\d+)(|:\d+)/
return [Metadata::relative_path($1), $2.to_i]
end
def first_caller_from_outside_rspec
self[:caller].detect {|l| l !~ /\/lib\/rspec\/core/}
end
def method_description_after_module?(parent_part, child_part)
return false unless parent_part.is_a?(Module)
child_part =~ /^(#|::|\.)/
end
def build_description_from(first_part = '', *parts)
description, _ = parts.inject([first_part.to_s, first_part]) do |(desc, last_part), this_part|
this_part = this_part.to_s
this_part = (' ' + this_part) unless method_description_after_module?(last_part, this_part)
[(desc + this_part), this_part]
end
description
end
end
# Mixed in to Metadata for an Example (extends MetadataHash) to support
# lazy evaluation of some values.
module ExampleMetadataHash
include MetadataHash
def described_class
self[:example_group].described_class
end
def full_description
build_description_from(self[:example_group][:full_description], *self[:description_args])
end
end
# Mixed in to Metadata for an ExampleGroup (extends MetadataHash) to
# support lazy evaluation of some values.
module GroupMetadataHash
include MetadataHash
def described_class
container_stack.each do |g|
[:described_class, :describes].each do |key|
if g.has_key?(key)
value = g[key]
return value unless value.nil?
end
end
end
container_stack.reverse.each do |g|
candidate = g[:description_args].first
return candidate unless String === candidate || Symbol === candidate
end
nil
end
def full_description
build_description_from(*container_stack.reverse.map {|a| a[:description_args]}.flatten)
end
def container_stack
@container_stack ||= begin
groups = [group = self]
while group.has_key?(:example_group)
groups << group[:example_group]
group = group[:example_group]
end
groups
end
end
end
def initialize(parent_group_metadata=nil)
if parent_group_metadata
update(parent_group_metadata)
store(:example_group, {:example_group => parent_group_metadata[:example_group].extend(GroupMetadataHash)}.extend(GroupMetadataHash))
else
store(:example_group, {}.extend(GroupMetadataHash))
end
yield self if block_given?
end
# @private
def process(*args)
user_metadata = args.last.is_a?(Hash) ? args.pop : {}
ensure_valid_keys(user_metadata)
self[:example_group].store(:description_args, args)
self[:example_group].store(:caller, user_metadata.delete(:caller) || caller)
update(user_metadata)
end
# @private
def for_example(description, user_metadata)
dup.extend(ExampleMetadataHash).configure_for_example(description, user_metadata)
end
# @private
def any_apply?(filters)
filters.any? {|k,v| filter_applies?(k,v)}
end
# @private
def all_apply?(filters)
filters.all? {|k,v| filter_applies?(k,v)}
end
# @private
def filter_applies?(key, value, metadata=self)
return metadata.filter_applies_to_any_value?(key, value) if Array === metadata[key] && !(Proc === value)
return metadata.line_number_filter_applies?(value) if key == :line_numbers
return metadata.location_filter_applies?(value) if key == :locations
return metadata.filters_apply?(key, value) if Hash === value
return false unless metadata.has_key?(key)
case value
when Regexp
metadata[key] =~ value
when Proc
case value.arity
when 0 then value.call
when 2 then value.call(metadata[key], metadata)
else value.call(metadata[key])
end
else
metadata[key].to_s == value.to_s
end
end
# @private
def filters_apply?(key, value)
value.all? {|k, v| filter_applies?(k, v, self[key])}
end
# @private
def filter_applies_to_any_value?(key, value)
self[key].any? {|v| filter_applies?(key, v, {key => value})}
end
# @private
def location_filter_applies?(locations)
# it ignores location filters for other files
line_number = example_group_declaration_line(locations)
line_number ? line_number_filter_applies?(line_number) : true
end
# @private
def line_number_filter_applies?(line_numbers)
preceding_declaration_lines = line_numbers.map {|n| RSpec.world.preceding_declaration_line(n)}
!(relevant_line_numbers & preceding_declaration_lines).empty?
end
protected
def configure_for_example(description, user_metadata)
store(:description_args, [description]) if description
store(:caller, user_metadata.delete(:caller) || caller)
update(user_metadata)
end
private
RESERVED_KEYS = [
:description,
:example_group,
:execution_result,
:file_path,
:full_description,
:line_number,
:location
]
def ensure_valid_keys(user_metadata)
RESERVED_KEYS.each do |key|
if user_metadata.has_key?(key)
raise <<-EOM
#{"*"*50}
:#{key} is not allowed
RSpec reserves some hash keys for its own internal use,
including :#{key}, which is used on:
#{caller(0)[4]}.
Here are all of RSpec's reserved hash keys:
#{RESERVED_KEYS.join("\n ")}
#{"*"*50}
EOM
end
end
end
def example_group_declaration_line(locations)
locations[File.expand_path(self[:example_group][:file_path])] if self[:example_group]
end
# TODO - make this a method on metadata - the problem is
# metadata[:example_group] is not always a kind of GroupMetadataHash.
def relevant_line_numbers(metadata=self)
[metadata[:line_number]] + (metadata[:example_group] ? relevant_line_numbers(metadata[:example_group]) : [])
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/shared_example_group.rb 0000644 0000041 0000041 00000013573 12261207027 023243 0 ustar www-data www-data module RSpec
module Core
module SharedExampleGroup
# @overload shared_examples(name, &block)
# @overload shared_examples(name, tags, &block)
#
# Wraps the `block` in a module which can then be included in example
# groups using `include_examples`, `include_context`, or
# `it_behaves_like`.
#
# @param [String] name to match when looking up this shared group
# @param block to be eval'd in a nested example group generated by `it_behaves_like`
#
# @example
#
# shared_examples "auditable" do
# it "stores an audit record on save!" do
# lambda { auditable.save! }.should change(Audit, :count).by(1)
# end
# end
#
# class Account do
# it_behaves_like "auditable" do
# def auditable; Account.new; end
# end
# end
#
# @see ExampleGroup.it_behaves_like
# @see ExampleGroup.include_examples
# @see ExampleGroup.include_context
def shared_examples(*args, &block)
SharedExampleGroup.registry.add_group(self, *args, &block)
end
alias_method :shared_context, :shared_examples
alias_method :share_examples_for, :shared_examples
alias_method :shared_examples_for, :shared_examples
# @deprecated
def share_as(name, &block)
RSpec.deprecate("Rspec::Core::SharedExampleGroup#share_as",
:replacement => "RSpec::SharedContext or shared_examples")
SharedExampleGroup.registry.add_const(self, name, &block)
end
def shared_example_groups
SharedExampleGroup.registry.shared_example_groups_for('main', *ancestors[0..-1])
end
module TopLevelDSL
def shared_examples(*args, &block)
SharedExampleGroup.registry.add_group('main', *args, &block)
end
alias_method :shared_context, :shared_examples
alias_method :share_examples_for, :shared_examples
alias_method :shared_examples_for, :shared_examples
def share_as(name, &block)
RSpec.deprecate("Rspec::Core::SharedExampleGroup#share_as",
:replacement => "RSpec::SharedContext or shared_examples")
SharedExampleGroup.registry.add_const('main', name, &block)
end
def shared_example_groups
SharedExampleGroup.registry.shared_example_groups_for('main')
end
end
def self.registry
@registry ||= Registry.new
end
# @private
#
# Used internally to manage the shared example groups and
# constants. We want to limit the number of methods we add
# to objects we don't own (main and Module) so this allows
# us to have helper methods that don't get added to those
# objects.
class Registry
def add_group(source, *args, &block)
ensure_block_has_source_location(block, caller[1])
if key? args.first
key = args.shift
warn_if_key_taken source, key, block
add_shared_example_group source, key, block
end
unless args.empty?
mod = Module.new
(class << mod; self; end).send :define_method, :extended do |host|
host.class_eval(&block)
end
RSpec.configuration.extend mod, *args
end
end
def add_const(source, name, &block)
if Object.const_defined?(name)
mod = Object.const_get(name)
raise_name_error unless mod.created_from_caller(caller)
end
mod = Module.new do
@shared_block = block
@caller_line = caller.last
def self.created_from_caller(other_caller)
@caller_line == other_caller.last
end
def self.included(kls)
kls.describe(&@shared_block)
kls.children.first.metadata[:shared_group_name] = name
end
end
shared_const = Object.const_set(name, mod)
add_shared_example_group source, shared_const, block
end
def shared_example_groups_for(*sources)
Collection.new(sources, shared_example_groups)
end
def shared_example_groups
@shared_example_groups ||= Hash.new { |hash,key| hash[key] = Hash.new }
end
def clear
shared_example_groups.clear
end
private
def add_shared_example_group(source, key, block)
shared_example_groups[source][key] = block
end
def key?(candidate)
[String, Symbol, Module].any? { |cls| cls === candidate }
end
def raise_name_error
raise NameError, "The first argument (#{name}) to share_as must be a legal name for a constant not already in use."
end
def warn_if_key_taken(source, key, new_block)
return unless existing_block = example_block_for(source, key)
Kernel.warn <<-WARNING.gsub(/^ +\|/, '')
|WARNING: Shared example group '#{key}' has been previously defined at:
| #{formatted_location existing_block}
|...and you are now defining it at:
| #{formatted_location new_block}
|The new definition will overwrite the original one.
WARNING
end
def formatted_location(block)
block.source_location.join ":"
end
def example_block_for(source, key)
shared_example_groups[source][key]
end
def ensure_block_has_source_location(block, caller_line)
return if block.respond_to?(:source_location)
block.extend Module.new {
define_method :source_location do
caller_line.split(':')
end
}
end
end
end
end
end
extend RSpec::Core::SharedExampleGroup::TopLevelDSL
Module.send(:include, RSpec::Core::SharedExampleGroup::TopLevelDSL)
rspec-core-2.14.7/lib/rspec/core/rake_task.rb 0000644 0000041 0000041 00000012402 12261207027 021000 0 ustar www-data www-data require 'rspec/core/backward_compatibility'
require 'rake'
require 'rake/tasklib'
require 'shellwords'
module RSpec
module Core
class RakeTask < ::Rake::TaskLib
include ::Rake::DSL if defined?(::Rake::DSL)
# Name of task.
#
# default:
# :spec
attr_accessor :name
# Glob pattern to match files.
#
# default:
# 'spec/**/*_spec.rb'
attr_accessor :pattern
# @deprecated
# Has no effect. The rake task now checks ENV['BUNDLE_GEMFILE'] instead.
def skip_bundler=(*)
deprecate("RSpec::Core::RakeTask#skip_bundler=")
end
# @deprecated
# Has no effect. The rake task now checks ENV['BUNDLE_GEMFILE'] instead.
def gemfile=(*)
deprecate("RSpec::Core::RakeTask#gemfile=", :replacement => 'ENV["BUNDLE_GEMFILE"]')
end
# @deprecated
# Use ruby_opts="-w" instead.
#
# When true, requests that the specs be run with the warning flag set.
# e.g. "ruby -w"
#
# default:
# false
def warning=(true_or_false)
deprecate("RSpec::Core::RakeTask#warning=", :replacement => 'ruby_opts="-w"')
@warning = true_or_false
end
# Whether or not to fail Rake when an error occurs (typically when examples fail).
#
# default:
# true
attr_accessor :fail_on_error
# A message to print to stderr when there are failures.
attr_accessor :failure_message
# Use verbose output. If this is set to true, the task will print the
# executed spec command to stdout.
#
# default:
# true
attr_accessor :verbose
# Use rcov for code coverage?
#
# Due to the many ways `rcov` can run, if this option is enabled, it is
# required that `require 'rspec/autorun'` appears in `spec_helper`.rb
#
# default:
# false
attr_accessor :rcov
# Path to rcov.
#
# default:
# 'rcov'
attr_accessor :rcov_path
# Command line options to pass to rcov.
#
# default:
# nil
attr_accessor :rcov_opts
# Command line options to pass to ruby.
#
# default:
# nil
attr_accessor :ruby_opts
# Path to rspec
#
# default:
# 'rspec'
attr_accessor :rspec_path
# Command line options to pass to rspec.
#
# default:
# nil
attr_accessor :rspec_opts
# @deprecated
# Use rspec_opts instead.
#
# Command line options to pass to rspec.
#
# default:
# nil
def spec_opts=(opts)
deprecate('RSpec::Core::RakeTask#spec_opts=', :replacement => 'rspec_opts=')
@rspec_opts = opts
end
def initialize(*args, &task_block)
setup_ivars(args)
desc "Run RSpec code examples" unless ::Rake.application.last_comment
task name, *args do |_, task_args|
RakeFileUtils.send(:verbose, verbose) do
task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
run_task verbose
end
end
end
def setup_ivars(args)
@name = args.shift || :spec
@rcov_opts, @ruby_opts, @rspec_opts = nil, nil, nil
@warning, @rcov = false, false
@verbose, @fail_on_error = true, true
@rcov_path = 'rcov'
@rspec_path = 'rspec'
@pattern = './spec{,/*/**}/*_spec.rb'
end
def run_task(verbose)
command = spec_command
begin
puts command if verbose
success = system(command)
rescue
puts failure_message if failure_message
end
abort("#{command} failed") if fail_on_error unless success
end
private
if "".respond_to?(:shellescape)
def shellescape(string)
string.shellescape
end
else # 1.8.6's shellwords doesn't provide shellescape :(.
def shellescape(string)
string.gsub(/"/, '\"').gsub(/'/, "\\\\'")
end
end
def files_to_run
if ENV['SPEC']
FileList[ ENV['SPEC'] ].sort
else
FileList[ pattern ].sort.map { |f| shellescape(f) }
end
end
def spec_command
cmd_parts = []
cmd_parts << RUBY
cmd_parts << ruby_opts
cmd_parts << "-w" if @warning
cmd_parts << "-S" << runner
cmd_parts << "-Ispec:lib" << rcov_opts if rcov
cmd_parts << files_to_run
cmd_parts << "--" if rcov && rspec_opts
cmd_parts << rspec_opts
cmd_parts.flatten.reject(&blank).join(" ")
end
def runner
rcov ? rcov_path : rspec_path
end
def blank
lambda {|s| s.nil? || s == ""}
end
def deprecate deprecated, opts = {}
# unless RSpec is loaded, deprecate won't work (simply requiring the
# deprecate file isn't enough) so this is a check for "is rspec already
# loaded?" "ok use the main deprecate hook" otherwise "simple fallback"
# Note that we don't need rspec to be loaded for the rake task to work
if RSpec.respond_to?(:deprecate)
RSpec.deprecate deprecated, opts
else
warn "DEPRECATION: #{deprecated} is deprecated."
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/drb_options.rb 0000644 0000041 0000041 00000005646 12261207027 021372 0 ustar www-data www-data # Builds command line arguments to pass to the rspec command over DRb
module RSpec::Core
# @private
class DrbOptions
def initialize(submitted_options, filter_manager)
@submitted_options = submitted_options
@filter_manager = filter_manager
end
def options
argv = []
argv << "--color" if @submitted_options[:color]
argv << "--profile" if @submitted_options[:profile_examples]
argv << "--backtrace" if @submitted_options[:full_backtrace]
argv << "--tty" if @submitted_options[:tty]
argv << "--fail-fast" if @submitted_options[:fail_fast]
argv << "--options" << @submitted_options[:custom_options_file] if @submitted_options[:custom_options_file]
argv << "--order" << @submitted_options[:order] if @submitted_options[:order]
add_failure_exit_code(argv)
add_full_description(argv)
add_line_numbers(argv)
add_filter(argv, :inclusion, @filter_manager.inclusions)
add_filter(argv, :exclusion, @filter_manager.exclusions)
add_formatters(argv)
add_libs(argv)
add_requires(argv)
argv + @submitted_options[:files_or_directories_to_run]
end
def add_failure_exit_code(argv)
if @submitted_options[:failure_exit_code]
argv << "--failure-exit-code" << @submitted_options[:failure_exit_code].to_s
end
end
def add_full_description(argv)
if @submitted_options[:full_description]
# The argument to --example is regexp-escaped before being stuffed
# into a regexp when received for the first time (see OptionParser).
# Hence, merely grabbing the source of this regexp will retain the
# backslashes, so we must remove them.
@submitted_options[:full_description].each do |description|
argv << "--example" << description.source.delete('\\')
end
end
end
def add_line_numbers(argv)
if @submitted_options[:line_numbers]
argv.push(*@submitted_options[:line_numbers].inject([]){|a,l| a << "--line_number" << l})
end
end
CONDITIONAL_FILTERS = [:if, :unless]
def add_filter(argv, name, hash)
hash.each_pair do |k, v|
next if CONDITIONAL_FILTERS.include?(k)
tag = name == :inclusion ? k.to_s : "~#{k}"
tag << ":#{v}" if v.is_a?(String)
argv << "--tag" << tag
end unless hash.empty?
end
def add_formatters(argv)
@submitted_options[:formatters].each do |pair|
argv << "--format" << pair[0]
argv << "--out" << pair[1] if pair[1]
end if @submitted_options[:formatters]
end
def add_libs(argv)
@submitted_options[:libs].each do |path|
argv << "-I" << path
end if @submitted_options[:libs]
end
def add_requires(argv)
@submitted_options[:requires].each do |path|
argv << "--require" << path
end if @submitted_options[:requires]
end
end
end
rspec-core-2.14.7/lib/rspec/core/example_group.rb 0000644 0000041 0000041 00000040611 12261207027 021706 0 ustar www-data www-data module RSpec
module Core
# ExampleGroup and {Example} are the main structural elements of
# rspec-core. Consider this example:
#
# describe Thing do
# it "does something" do
# end
# end
#
# The object returned by `describe Thing` is a subclass of ExampleGroup.
# The object returned by `it "does something"` is an instance of Example,
# which serves as a wrapper for an instance of the ExampleGroup in which it
# is declared.
class ExampleGroup
extend MetadataHashBuilder::WithDeprecationWarning
extend Extensions::ModuleEvalWithArgs
extend Hooks
include MemoizedHelpers
include Extensions::InstanceEvalWithArgs
include Pending
include SharedExampleGroup
extend SharedExampleGroup
# @private
def self.world
RSpec.world
end
# @private
def self.register
world.register(self)
end
class << self
# @private
def self.delegate_to_metadata(*names)
names.each do |name|
define_method name do
metadata[:example_group][name]
end
end
end
def description
description = metadata[:example_group][:description]
RSpec.configuration.format_docstrings_block.call(description)
end
delegate_to_metadata :described_class, :file_path
alias_method :display_name, :description
# @private
alias_method :describes, :described_class
# @private
# @macro [attach] define_example_method
# @param [String] name
# @param [Hash] extra_options
# @param [Block] implementation
def self.define_example_method(name, extra_options={})
module_eval(<<-END_RUBY, __FILE__, __LINE__)
def #{name}(desc=nil, *args, &block)
options = build_metadata_hash_from(args)
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
end
END_RUBY
end
# Defines an example within a group.
define_example_method :example
# Defines an example within a group.
#
# @see example
define_example_method :it
# Defines an example within a group.
# This is here primarily for backward compatibility with early versions
# of RSpec which used `context` and `specify` instead of `describe` and
# `it`.
define_example_method :specify
# Shortcut to define an example with `:focus` => true
define_example_method :focus, :focused => true, :focus => true
# Shortcut to define an example with `:focus` => true
define_example_method :focused, :focused => true, :focus => true
# Shortcut to define an example with `:focus` => true
# @see example
define_example_method :fit, :focused => true, :focus => true
# Shortcut to define an example with :pending => true
define_example_method :pending, :pending => true
# Shortcut to define an example with :pending => 'Temporarily disabled with xexample'
define_example_method :xexample, :pending => 'Temporarily disabled with xexample'
# Shortcut to define an example with :pending => 'Temporarily disabled with xit'
define_example_method :xit, :pending => 'Temporarily disabled with xit'
# Shortcut to define an example with :pending => 'Temporarily disabled with xspecify'
define_example_method :xspecify, :pending => 'Temporarily disabled with xspecify'
# Works like `alias_method :name, :example` with the added benefit of
# assigning default metadata to the generated example.
#
# @note Use with caution. This extends the language used in your
# specs, but does not add any additional documentation. We use this
# in rspec to define methods like `focus` and `xit`, but we also add
# docs for those methods.
def alias_example_to name, extra={}
(class << self; self; end).define_example_method name, extra
end
# @private
# @macro [attach] define_nested_shared_group_method
#
# @see SharedExampleGroup
def self.define_nested_shared_group_method(new_name, report_label=nil)
module_eval(<<-END_RUBY, __FILE__, __LINE__)
def #{new_name}(name, *args, &customization_block)
group = describe("#{report_label || "it should behave like"} \#{name}") do
find_and_eval_shared("examples", name, *args, &customization_block)
end
group.metadata[:shared_group_name] = name
group
end
END_RUBY
end
# Generates a nested example group and includes the shared content
# mapped to `name` in the nested group.
define_nested_shared_group_method :it_behaves_like, "behaves like"
# Generates a nested example group and includes the shared content
# mapped to `name` in the nested group.
define_nested_shared_group_method :it_should_behave_like
# Works like `alias_method :name, :it_behaves_like` with the added
# benefit of assigning default metadata to the generated example.
#
# @note Use with caution. This extends the language used in your
# specs, but does not add any additional documentation. We use this
# in rspec to define `it_should_behave_like` (for backward
# compatibility), but we also add docs for that method.
def alias_it_behaves_like_to name, *args, &block
(class << self; self; end).define_nested_shared_group_method name, *args, &block
end
end
# Includes shared content mapped to `name` directly in the group in which
# it is declared, as opposed to `it_behaves_like`, which creates a nested
# group. If given a block, that block is also eval'd in the current context.
#
# @see SharedExampleGroup
def self.include_context(name, *args, &block)
find_and_eval_shared("context", name, *args, &block)
end
# Includes shared content mapped to `name` directly in the group in which
# it is declared, as opposed to `it_behaves_like`, which creates a nested
# group. If given a block, that block is also eval'd in the current context.
#
# @see SharedExampleGroup
def self.include_examples(name, *args, &block)
find_and_eval_shared("examples", name, *args, &block)
end
# @private
def self.find_and_eval_shared(label, name, *args, &customization_block)
raise ArgumentError, "Could not find shared #{label} #{name.inspect}" unless
shared_block = shared_example_groups[name]
module_eval_with_args(*args, &shared_block)
module_eval(&customization_block) if customization_block
end
# @private
def self.examples
@examples ||= []
end
# @private
def self.filtered_examples
world.filtered_examples[self]
end
# @private
def self.descendant_filtered_examples
@descendant_filtered_examples ||= filtered_examples + children.inject([]){|l,c| l + c.descendant_filtered_examples}
end
# The [Metadata](Metadata) object associated with this group.
# @see Metadata
def self.metadata
@metadata if defined?(@metadata)
end
# @private
# @return [Metadata] belonging to the parent of a nested {ExampleGroup}
def self.superclass_metadata
@superclass_metadata ||= self.superclass.respond_to?(:metadata) ? self.superclass.metadata : nil
end
# Generates a subclass of this example group which inherits
# everything except the examples themselves.
#
# ## Examples
#
# describe "something" do # << This describe method is defined in
# # << RSpec::Core::DSL, included in the
# # << global namespace
# before do
# do_something_before
# end
#
# let(:thing) { Thing.new }
#
# describe "attribute (of something)" do
# # examples in the group get the before hook
# # declared above, and can access `thing`
# end
# end
#
# @see DSL#describe
def self.describe(*args, &example_group_block)
@_subclass_count ||= 0
@_subclass_count += 1
args << {} unless args.last.is_a?(Hash)
args.last.update(:example_group_block => example_group_block)
# TODO 2010-05-05: Because we don't know if const_set is thread-safe
child = const_set(
"Nested_#{@_subclass_count}",
subclass(self, args, &example_group_block)
)
children << child
child
end
class << self
alias_method :context, :describe
end
# @private
def self.subclass(parent, args, &example_group_block)
subclass = Class.new(parent)
subclass.set_it_up(*args)
subclass.module_eval(&example_group_block) if example_group_block
# The LetDefinitions module must be included _after_ other modules
# to ensure that it takes precendence when there are name collisions.
# Thus, we delay including it until after the example group block
# has been eval'd.
MemoizedHelpers.define_helpers_on(subclass)
subclass
end
# @private
def self.children
@children ||= [].extend(Extensions::Ordered::ExampleGroups)
end
# @private
def self.descendants
@_descendants ||= [self] + children.inject([]) {|list, c| list + c.descendants}
end
## @private
def self.parent_groups
@parent_groups ||= ancestors.select {|a| a < RSpec::Core::ExampleGroup}
end
# @private
def self.top_level?
@top_level ||= superclass == ExampleGroup
end
# @private
def self.ensure_example_groups_are_configured
unless defined?(@@example_groups_configured)
RSpec.configuration.configure_mock_framework
RSpec.configuration.configure_expectation_framework
@@example_groups_configured = true
end
end
# @private
def self.set_it_up(*args)
# Ruby 1.9 has a bug that can lead to infinite recursion and a
# SystemStackError if you include a module in a superclass after
# including it in a subclass: https://gist.github.com/845896
# To prevent this, we must include any modules in RSpec::Core::ExampleGroup
# before users create example groups and have a chance to include
# the same module in a subclass of RSpec::Core::ExampleGroup.
# So we need to configure example groups here.
ensure_example_groups_are_configured
symbol_description = args.shift if args.first.is_a?(Symbol)
args << build_metadata_hash_from(args)
args.unshift(symbol_description) if symbol_description
@metadata = RSpec::Core::Metadata.new(superclass_metadata).process(*args)
hooks.register_globals(self, RSpec.configuration.hooks)
world.configure_group(self)
end
# @private
def self.before_all_ivars
@before_all_ivars ||= {}
end
# @private
def self.store_before_all_ivars(example_group_instance)
return if example_group_instance.instance_variables.empty?
example_group_instance.instance_variables.each { |ivar|
before_all_ivars[ivar] = example_group_instance.instance_variable_get(ivar)
}
end
# @private
def self.assign_before_all_ivars(ivars, example_group_instance)
ivars.each { |ivar, val| example_group_instance.instance_variable_set(ivar, val) }
end
# @private
def self.run_before_all_hooks(example_group_instance)
return if descendant_filtered_examples.empty?
begin
assign_before_all_ivars(superclass.before_all_ivars, example_group_instance)
BeforeAllMemoizedHash.isolate_for_before_all(example_group_instance) do
run_hook(:before, :all, example_group_instance)
end
ensure
store_before_all_ivars(example_group_instance)
end
end
# @private
def self.run_around_each_hooks(example, initial_procsy)
run_hook(:around, :each, example, initial_procsy)
end
# @private
def self.run_before_each_hooks(example)
run_hook(:before, :each, example)
end
# @private
def self.run_after_each_hooks(example)
run_hook(:after, :each, example)
end
# @private
def self.run_after_all_hooks(example_group_instance)
return if descendant_filtered_examples.empty?
assign_before_all_ivars(before_all_ivars, example_group_instance)
run_hook(:after, :all, example_group_instance)
end
# Runs all the examples in this group
def self.run(reporter)
if RSpec.wants_to_quit
RSpec.clear_remaining_example_groups if top_level?
return
end
reporter.example_group_started(self)
begin
run_before_all_hooks(new)
result_for_this_group = run_examples(reporter)
results_for_descendants = children.ordered.map {|child| child.run(reporter)}.all?
result_for_this_group && results_for_descendants
rescue Exception => ex
RSpec.wants_to_quit = true if fail_fast?
fail_filtered_examples(ex, reporter)
ensure
run_after_all_hooks(new)
before_all_ivars.clear
reporter.example_group_finished(self)
end
end
# @private
def self.run_examples(reporter)
filtered_examples.ordered.map do |example|
next if RSpec.wants_to_quit
instance = new
set_ivars(instance, before_all_ivars)
succeeded = example.run(instance, reporter)
RSpec.wants_to_quit = true if fail_fast? && !succeeded
succeeded
end.all?
end
# @private
def self.fail_filtered_examples(exception, reporter)
filtered_examples.each { |example| example.fail_with_exception(reporter, exception) }
children.each do |child|
reporter.example_group_started(child)
child.fail_filtered_examples(exception, reporter)
reporter.example_group_finished(child)
end
false
end
# @private
def self.fail_fast?
RSpec.configuration.fail_fast?
end
# @private
def self.any_apply?(filters)
metadata.any_apply?(filters)
end
# @private
def self.all_apply?(filters)
metadata.all_apply?(filters)
end
# @private
def self.declaration_line_numbers
@declaration_line_numbers ||= [metadata[:example_group][:line_number]] +
examples.collect {|e| e.metadata[:line_number]} +
children.inject([]) {|l,c| l + c.declaration_line_numbers}
end
# @private
def self.top_level_description
parent_groups.last.description
end
# @private
def self.set_ivars(instance, ivars)
ivars.each {|name, value| instance.instance_variable_set(name, value)}
end
# @attr_reader
# Returns the {Example} object that wraps this instance of
# `ExampleGroup`
attr_accessor :example
# @deprecated use {ExampleGroup#example}
def running_example
RSpec.deprecate("running_example",
:replacement => "example")
example
end
# Returns the class or module passed to the `describe` method (or alias).
# Returns nil if the subject is not a class or module.
# @example
# describe Thing do
# it "does something" do
# described_class == Thing
# end
# end
#
#
def described_class
self.class.described_class
end
# @private
# instance_evals the block, capturing and reporting an exception if
# raised
def instance_eval_with_rescue(context = nil, &hook)
begin
instance_eval(&hook)
rescue Exception => e
raise unless example
example.set_exception(e, context)
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/backward_compatibility.rb 0000644 0000041 0000041 00000002525 12261207027 023550 0 ustar www-data www-data module RSpec
module Core
# @private
module ConstMissing
# Used to print deprecation warnings for Rspec and Spec constants (use
# RSpec instead)
def const_missing(name)
case name
when :Rspec, :Spec
RSpec.deprecate(name.to_s, :replacement => "RSpec")
RSpec
else
begin
super
rescue Exception => e
e.backtrace.reject! {|l| l =~ Regexp.compile(__FILE__) }
raise e
end
end
end
end
end
module Runner
# @deprecated use RSpec.configure instead.
def self.configure(&block)
RSpec.deprecate("Spec::Runner.configure", :replacement => "RSpec.configure")
RSpec.configure(&block)
end
end
# @private
module Rake
# Used to print deprecation warnings for Rake::SpecTask constant (use
# RSpec::Core::RakeTask instead)
def self.const_missing(name)
case name
when :SpecTask
RSpec.deprecate("Spec::Rake::SpecTask", :replacement => "RSpec::Core::RakeTask")
require 'rspec/core/rake_task'
RSpec::Core::RakeTask
else
begin
super
rescue Exception => e
e.backtrace.reject! {|l| l =~ Regexp.compile(__FILE__) }
raise e
end
end
end
end
end
Object.extend(RSpec::Core::ConstMissing)
rspec-core-2.14.7/lib/rspec/core/version.rb 0000644 0000041 0000041 00000000131 12261207027 020515 0 ustar www-data www-data module RSpec
module Core
module Version
STRING = '2.14.7'
end
end
end
rspec-core-2.14.7/lib/rspec/core/drb_command_line.rb 0000644 0000041 0000041 00000001151 12261207027 022307 0 ustar www-data www-data require 'drb/drb'
require 'rspec/core/drb_options'
module RSpec
module Core
class DRbCommandLine
def initialize(options)
@options = options
end
def drb_port
@options.options[:drb_port] || ENV['RSPEC_DRB'] || 8989
end
def run(err, out)
begin
DRb.start_service("druby://localhost:0")
rescue SocketError, Errno::EADDRNOTAVAIL
DRb.start_service("druby://:0")
end
spec_server = DRbObject.new_with_uri("druby://127.0.0.1:#{drb_port}")
spec_server.run(@options.drb_argv, err, out)
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/ 0000755 0000041 0000041 00000000000 12261207027 020676 5 ustar www-data www-data rspec-core-2.14.7/lib/rspec/core/formatters/html_formatter.rb 0000644 0000041 0000041 00000010620 12261207027 024251 0 ustar www-data www-data require 'rspec/core/formatters/base_text_formatter'
require 'rspec/core/formatters/html_printer'
module RSpec
module Core
module Formatters
class HtmlFormatter < BaseTextFormatter
def initialize(output)
super(output)
@example_group_number = 0
@example_number = 0
@header_red = nil
@printer = HtmlPrinter.new(output)
end
private
def method_missing(m, *a, &b)
# no-op
end
public
def message(message)
end
# The number of the currently running example_group
def example_group_number
@example_group_number
end
# The number of the currently running example (a global counter)
def example_number
@example_number
end
def start(example_count)
super(example_count)
@printer.print_html_start
@printer.flush
end
def example_group_started(example_group)
super(example_group)
@example_group_red = false
@example_group_number += 1
unless example_group_number == 1
@printer.print_example_group_end
end
@printer.print_example_group_start( example_group_number, example_group.description, example_group.parent_groups.size )
@printer.flush
end
def start_dump
@printer.print_example_group_end
@printer.flush
end
def example_started(example)
super(example)
@example_number += 1
end
def example_passed(example)
@printer.move_progress(percent_done)
@printer.print_example_passed( example.description, example.execution_result[:run_time] )
@printer.flush
end
def example_failed(example)
super(example)
unless @header_red
@header_red = true
@printer.make_header_red
end
unless @example_group_red
@example_group_red = true
@printer.make_example_group_header_red(example_group_number)
end
@printer.move_progress(percent_done)
exception = example.metadata[:execution_result][:exception]
exception_details = if exception
{
:message => exception.message,
:backtrace => format_backtrace(exception.backtrace, example).join("\n")
}
else
false
end
extra = extra_failure_content(exception)
@printer.print_example_failed(
example.execution_result[:pending_fixed],
example.description,
example.execution_result[:run_time],
@failed_examples.size,
exception_details,
(extra == "") ? false : extra,
true
)
@printer.flush
end
def example_pending(example)
@printer.make_header_yellow unless @header_red
@printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
@printer.move_progress(percent_done)
@printer.print_example_pending( example.description, example.metadata[:execution_result][:pending_message] )
@printer.flush
end
# Override this method if you wish to output extra HTML for a failed spec. For example, you
# could output links to images or other files produced during the specs.
#
def extra_failure_content(exception)
require 'rspec/core/formatters/snippet_extractor'
backtrace = exception.backtrace.map {|line| backtrace_line(line)}
backtrace.compact!
@snippet_extractor ||= SnippetExtractor.new
" #{@snippet_extractor.snippet(backtrace)}
"
end
def percent_done
result = 100.0
if @example_count > 0
result = (((example_number).to_f / @example_count.to_f * 1000).to_i / 10.0).to_f
end
result
end
def dump_failures
end
def dump_pending
end
def dump_summary(duration, example_count, failure_count, pending_count)
@printer.print_summary(
dry_run?,
duration,
example_count,
failure_count,
pending_count
)
@printer.flush
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/documentation_formatter.rb 0000644 0000041 0000041 00000003403 12261207027 026157 0 ustar www-data www-data require 'rspec/core/formatters/base_text_formatter'
module RSpec
module Core
module Formatters
class DocumentationFormatter < BaseTextFormatter
def initialize(output)
super(output)
@group_level = 0
end
def example_group_started(example_group)
super(example_group)
output.puts if @group_level == 0
output.puts "#{current_indentation}#{example_group.description.strip}"
@group_level += 1
end
def example_group_finished(example_group)
@group_level -= 1
end
def example_passed(example)
super(example)
output.puts passed_output(example)
end
def example_pending(example)
super(example)
output.puts pending_output(example, example.execution_result[:pending_message])
end
def example_failed(example)
super(example)
output.puts failure_output(example, example.execution_result[:exception])
end
def failure_output(example, exception)
failure_color("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})")
end
def next_failure_index
@next_failure_index ||= 0
@next_failure_index += 1
end
def passed_output(example)
success_color("#{current_indentation}#{example.description.strip}")
end
def pending_output(example, message)
pending_color("#{current_indentation}#{example.description.strip} (PENDING: #{message})")
end
def current_indentation
' ' * @group_level
end
def example_group_chain
example_group.parent_groups.reverse
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/deprecation_formatter.rb 0000644 0000041 0000041 00000002416 12261207027 025606 0 ustar www-data www-data module RSpec
module Core
module Formatters
class DeprecationFormatter
def initialize(deprecation_stream=$stderr, summary_stream=$stdout)
@deprecation_stream = deprecation_stream
@summary_stream = summary_stream
@count = 0
end
def start(example_count=nil)
#no-op to fix #966
end
def deprecation(data)
@count += 1
if data[:message]
@deprecation_stream.print data[:message]
else
@deprecation_stream.print "DEPRECATION: " unless File === @deprecation_stream
@deprecation_stream.print "#{data[:deprecated]} is deprecated."
@deprecation_stream.print " Use #{data[:replacement]} instead." if data[:replacement]
@deprecation_stream.print " Called from #{data[:call_site]}." if data[:call_site]
@deprecation_stream.puts
end
end
def deprecation_summary
if @count > 0 && File === @deprecation_stream
@summary_stream.print "\n#{@count} deprecation"
@summary_stream.print "s" if @count > 1
@summary_stream.print " logged to "
@summary_stream.puts @deprecation_stream.path
end
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/base_text_formatter.rb 0000644 0000041 0000041 00000026652 12261207027 025277 0 ustar www-data www-data require 'rspec/core/formatters/base_formatter'
require 'set'
module RSpec
module Core
module Formatters
# Base for all of RSpec's built-in formatters. See RSpec::Core::Formatters::BaseFormatter
# to learn more about all of the methods called by the reporter.
#
# @see RSpec::Core::Formatters::BaseFormatter
# @see RSpec::Core::Reporter
class BaseTextFormatter < BaseFormatter
def message(message)
output.puts message
end
def dump_failures
return if failed_examples.empty?
output.puts
output.puts "Failures:"
failed_examples.each_with_index do |example, index|
output.puts
pending_fixed?(example) ? dump_pending_fixed(example, index) : dump_failure(example, index)
dump_backtrace(example)
end
end
# @api public
#
# Colorizes the output red for failure, yellow for
# pending, and green otherwise.
#
# @param [String] string
def colorise_summary(summary)
if failure_count > 0
color(summary, RSpec.configuration.failure_color)
elsif pending_count > 0
color(summary, RSpec.configuration.pending_color)
else
color(summary, RSpec.configuration.success_color)
end
end
def dump_summary(duration, example_count, failure_count, pending_count)
super(duration, example_count, failure_count, pending_count)
dump_profile unless mute_profile_output?(failure_count)
output.puts "\nFinished in #{format_duration(duration)}\n"
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
dump_commands_to_rerun_failed_examples
end
# @api public
#
# Outputs commands which can be used to re-run failed examples.
#
def dump_commands_to_rerun_failed_examples
return if failed_examples.empty?
output.puts
output.puts("Failed examples:")
output.puts
failed_examples.each do |example|
output.puts(failure_color("rspec #{RSpec::Core::Metadata::relative_path(example.location)}") + " " + detail_color("# #{example.full_description}"))
end
end
# @api public
#
# Outputs the slowest examples and example groups in a report when using `--profile COUNT` (default 10).
#
def dump_profile
dump_profile_slowest_examples
dump_profile_slowest_example_groups
end
def dump_profile_slowest_examples
number_of_examples = RSpec.configuration.profile_examples
sorted_examples = examples.sort_by {|example|
example.execution_result[:run_time] }.reverse.first(number_of_examples)
total, slows = [examples, sorted_examples].map {|exs|
exs.inject(0.0) {|i, e| i + e.execution_result[:run_time] }}
time_taken = slows / total
percentage = '%.1f' % ((time_taken.nan? ? 0.0 : time_taken) * 100)
output.puts "\nTop #{sorted_examples.size} slowest examples (#{format_seconds(slows)} seconds, #{percentage}% of total time):\n"
sorted_examples.each do |example|
output.puts " #{example.full_description}"
output.puts detail_color(" #{failure_color(format_seconds(example.execution_result[:run_time]))} #{failure_color("seconds")} #{format_caller(example.location)}")
end
end
def dump_profile_slowest_example_groups
number_of_examples = RSpec.configuration.profile_examples
example_groups = {}
examples.each do |example|
location = example.example_group.parent_groups.last.metadata[:example_group][:location]
example_groups[location] ||= Hash.new(0)
example_groups[location][:total_time] += example.execution_result[:run_time]
example_groups[location][:count] += 1
example_groups[location][:description] = example.example_group.top_level_description unless example_groups[location].has_key?(:description)
end
# stop if we've only one example group
return if example_groups.keys.length <= 1
example_groups.each do |loc, hash|
hash[:average] = hash[:total_time].to_f / hash[:count]
end
sorted_groups = example_groups.sort_by {|_, hash| -hash[:average]}.first(number_of_examples)
output.puts "\nTop #{sorted_groups.size} slowest example groups:"
sorted_groups.each do |loc, hash|
average = "#{failure_color(format_seconds(hash[:average]))} #{failure_color("seconds")} average"
total = "#{format_seconds(hash[:total_time])} seconds"
count = pluralize(hash[:count], "example")
output.puts " #{hash[:description]}"
output.puts detail_color(" #{average} (#{total} / #{count}) #{loc}")
end
end
# @api public
#
# Outputs summary with number of examples, failures and pending.
#
def summary_line(example_count, failure_count, pending_count)
summary = pluralize(example_count, "example")
summary << ", " << pluralize(failure_count, "failure")
summary << ", #{pending_count} pending" if pending_count > 0
summary
end
def dump_pending
unless pending_examples.empty?
output.puts
output.puts "Pending:"
pending_examples.each do |pending_example|
output.puts pending_color(" #{pending_example.full_description}")
output.puts detail_color(" # #{pending_example.execution_result[:pending_message]}")
output.puts detail_color(" # #{format_caller(pending_example.location)}")
if pending_example.execution_result[:exception] \
&& RSpec.configuration.show_failures_in_pending_blocks?
dump_failure_info(pending_example)
dump_backtrace(pending_example)
end
end
end
end
def seed(number)
output.puts
output.puts "Randomized with seed #{number}"
output.puts
end
def close
output.close if IO === output && output != $stdout
end
VT100_COLORS = {
:black => 30,
:red => 31,
:green => 32,
:yellow => 33,
:blue => 34,
:magenta => 35,
:cyan => 36,
:white => 37
}
VT100_COLOR_CODES = VT100_COLORS.values.to_set
def color_code_for(code_or_symbol)
if VT100_COLOR_CODES.include?(code_or_symbol)
code_or_symbol
else
VT100_COLORS.fetch(code_or_symbol) do
color_code_for(:white)
end
end
end
def colorize(text, code_or_symbol)
"\e[#{color_code_for(code_or_symbol)}m#{text}\e[0m"
end
protected
def bold(text)
color_enabled? ? "\e[1m#{text}\e[0m" : text
end
def color(text, color_code)
color_enabled? ? colorize(text, color_code) : text
end
def failure_color(text)
color(text, RSpec.configuration.failure_color)
end
def success_color(text)
color(text, RSpec.configuration.success_color)
end
def pending_color(text)
color(text, RSpec.configuration.pending_color)
end
def fixed_color(text)
color(text, RSpec.configuration.fixed_color)
end
def detail_color(text)
color(text, RSpec.configuration.detail_color)
end
def default_color(text)
color(text, RSpec.configuration.default_color)
end
def red(text)
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#red", :replacement => "#failure_color")
color(text, :red)
end
def green(text)
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#green", :replacement => "#success_color")
color(text, :green)
end
def yellow(text)
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#yellow", :replacement => "#pending_color")
color(text, :yellow)
end
def blue(text)
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#blue", :replacement => "#fixed_color")
color(text, :blue)
end
def magenta(text)
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#magenta")
color(text, :magenta)
end
def cyan(text)
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#cyan", :replacement => "#detail_color")
color(text, :cyan)
end
def white(text)
RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#white", :replacement => "#default_color")
color(text, :white)
end
def short_padding
' '
end
def long_padding
' '
end
private
def format_caller(caller_info)
backtrace_line(caller_info.to_s.split(':in `block').first)
end
def dump_backtrace(example)
format_backtrace(example.execution_result[:exception].backtrace, example).each do |backtrace_info|
output.puts detail_color("#{long_padding}# #{backtrace_info}")
end
end
def dump_pending_fixed(example, index)
output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
output.puts fixed_color("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
end
def pending_fixed?(example)
example.execution_result[:pending_fixed]
end
def dump_failure(example, index)
output.puts "#{short_padding}#{index.next}) #{example.full_description}"
dump_failure_info(example)
end
def dump_failure_info(example)
exception = example.execution_result[:exception]
exception_class_name = exception_class_name_for(exception)
output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}"
output.puts "#{long_padding}#{failure_color(exception_class_name)}:" unless exception_class_name =~ /RSpec/
exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{failure_color(line)}" } if exception.message
if shared_group = find_shared_group(example)
dump_shared_failure_info(shared_group)
end
end
def exception_class_name_for(exception)
name = exception.class.name.to_s
name ="(anonymous error class)" if name == ''
name
end
def dump_shared_failure_info(group)
output.puts "#{long_padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
"#{backtrace_line(group.metadata[:example_group][:location])}"
end
def find_shared_group(example)
group_and_parent_groups(example).find {|group| group.metadata[:shared_group_name]}
end
def group_and_parent_groups(example)
example.example_group.parent_groups + [example.example_group]
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/snippet_extractor.rb 0000644 0000041 0000041 00000006366 12261207027 025013 0 ustar www-data www-data module RSpec
module Core
module Formatters
# @api private
#
# Extracts code snippets by looking at the backtrace of the passed error and applies synax highlighting and line numbers using html.
class SnippetExtractor
class NullConverter; def convert(code, pre); code; end; end
begin
require 'syntax/convertors/html'
@@converter = Syntax::Convertors::HTML.for_syntax "ruby"
rescue LoadError
@@converter = NullConverter.new
end
# @api private
#
# Extract lines of code corresponding to a backtrace.
#
# @param [String] backtrace the backtrace from a test failure
# @return [String] highlighted code snippet indicating where the test failure occured
#
# @see #post_process
def snippet(backtrace)
raw_code, line = snippet_for(backtrace[0])
highlighted = @@converter.convert(raw_code, false)
highlighted << "\n" if @@converter.is_a?(NullConverter)
post_process(highlighted, line)
end
# @api private
#
# Create a snippet from a line of code.
#
# @param [String] error_line file name with line number (i.e. 'foo_spec.rb:12')
# @return [String] lines around the target line within the file
#
# @see #lines_around
def snippet_for(error_line)
if error_line =~ /(.*):(\d+)/
file = $1
line = $2.to_i
[lines_around(file, line), line]
else
["# Couldn't get snippet for #{error_line}", 1]
end
end
# @api private
#
# Extract lines of code centered around a particular line within a source file.
#
# @param [String] file filename
# @param [Fixnum] line line number
# @return [String] lines around the target line within the file (2 above and 1 below).
def lines_around(file, line)
if File.file?(file)
lines = File.read(file).split("\n")
min = [0, line-3].max
max = [line+1, lines.length-1].min
selected_lines = []
selected_lines.join("\n")
lines[min..max].join("\n")
else
"# Couldn't get snippet for #{file}"
end
rescue SecurityError
"# Couldn't get snippet for #{file}"
end
# @api private
#
# Adds line numbers to all lines and highlights the line where the failure occurred using html `span` tags.
#
# @param [String] highlighted syntax-highlighted snippet surrounding the offending line of code
# @param [Fixnum] offending_line line where failure occured
# @return [String] completed snippet
def post_process(highlighted, offending_line)
new_lines = []
highlighted.split("\n").each_with_index do |line, i|
new_line = "#{offending_line+i-2}#{line}"
new_line = "#{new_line}" if i == 2
new_lines << new_line
end
new_lines.join("\n")
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/base_formatter.rb 0000644 0000041 0000041 00000016315 12261207027 024226 0 ustar www-data www-data require 'rspec/core/formatters/helpers'
require 'stringio'
module RSpec
module Core
module Formatters
# RSpec's built-in formatters are all subclasses of RSpec::Core::Formatters::BaseTextFormatter,
# but the BaseTextFormatter documents all of the methods needed to be implemented by a formatter,
# as they are called from the reporter.
#
# @see RSpec::Core::Formatters::BaseTextFormatter
# @see RSpec::Core::Reporter
class BaseFormatter
include Helpers
attr_accessor :example_group
attr_reader :duration, :examples, :output
attr_reader :example_count, :pending_count, :failure_count
attr_reader :failed_examples, :pending_examples
# @api public
#
# @param output
def initialize(output)
@output = output || StringIO.new
@example_count = @pending_count = @failure_count = 0
@examples = []
@failed_examples = []
@pending_examples = []
@example_group = nil
end
# @api public
#
# This method is invoked before any examples are run, right after
# they have all been collected. This can be useful for special
# formatters that need to provide progress on feedback (graphical ones).
#
# This will only be invoked once, and the next one to be invoked
# is {#example_group_started}.
#
# @param example_count
def start(example_count)
start_sync_output
@example_count = example_count
end
# @api public
#
# This method is invoked at the beginning of the execution of each example group.
#
# @param example_group subclass of `RSpec::Core::ExampleGroup`
#
# The next method to be invoked after this is {#example_passed},
# {#example_pending}, or {#example_group_finished}.
#
# @param example_group
def example_group_started(example_group)
@example_group = example_group
end
# @api public
#
# Invoked at the end of the execution of each example group.
#
# @param example_group subclass of `RSpec::Core::ExampleGroup`
def example_group_finished(example_group)
end
# @api public
#
# Invoked at the beginning of the execution of each example.
#
# @param example instance of subclass of `RSpec::Core::ExampleGroup`
# @return [Array]
def example_started(example)
examples << example
end
# @api public
#
# Invoked when an example passes.
#
# @param example instance of subclass of `RSpec::Core::ExampleGroup`
def example_passed(example)
end
# Invoked when an example is pending.
#
# @param example instance of subclass of `RSpec::Core::ExampleGroup`
# @return [Array]
def example_pending(example)
@pending_examples << example
end
# @api public
#
# Invoked when an example fails.
#
# @param example instance of subclass of `RSpec::Core::ExampleGroup`
# @return [Array]
def example_failed(example)
@failed_examples << example
end
# @api public
#
# Used by the reporter to send messages to the output stream.
#
# @param [String] message
def message(message)
end
# @api public
#
# Invoked after all examples have executed, before dumping post-run reports.
#
# @return [nil]
def stop
end
# @api public
#
# This method is invoked after all of the examples have executed. The next method
# to be invoked after this one is {#dump_failures}
# (BaseTextFormatter then calls {#dump_failure} once for each failed example.)
#
# @return [nil]
def start_dump
end
# @api public
#
# Dumps detailed information about each example failure.
#
# @return [nil]
def dump_failures
end
# @api public
#
# This method is invoked after the dumping of examples and failures. Each parameter
# is assigned to a corresponding attribute.
#
# @param duration
# @param example_count
# @param failure_count
# @param pending_count
def dump_summary(duration, example_count, failure_count, pending_count)
@duration = duration
@example_count = example_count
@failure_count = failure_count
@pending_count = pending_count
end
# @api public
#
# Outputs a report of pending examples. This gets invoked
# after the summary if option is set to do so.
#
# @return [nil]
def dump_pending
end
# @private not intended for use outside RSpec.
def seed(number)
end
# @api public
#
# Invoked at the very end, `close` allows the formatter to clean
# up resources, e.g. open streams, etc.
def close
restore_sync_output
end
# @api public
#
# Formats the given backtrace based on configuration and
# the metadata of the given example.
def format_backtrace(backtrace, example)
super(backtrace, example.metadata)
end
protected
def configuration
RSpec.configuration
end
def read_failed_line(exception, example)
unless matching_line = find_failed_line(exception.backtrace, example.file_path)
return "Unable to find matching line from backtrace"
end
file_path, line_number = matching_line.match(/(.+?):(\d+)(|:\d+)/)[1..2]
if File.exist?(file_path)
File.readlines(file_path)[line_number.to_i - 1] ||
"Unable to find matching line in #{file_path}"
else
"Unable to find #{file_path} to read failed line"
end
rescue SecurityError
"Unable to read failed line"
end
def find_failed_line(backtrace, path)
path = File.expand_path(path)
backtrace.detect { |line|
match = line.match(/(.+?):(\d+)(|:\d+)/)
match && match[1].downcase == path.downcase
}
end
def start_sync_output
@old_sync, output.sync = output.sync, true if output_supports_sync
end
def restore_sync_output
output.sync = @old_sync if output_supports_sync and !output.closed?
end
def output_supports_sync
output.respond_to?(:sync=)
end
def profile_examples?
configuration.profile_examples
end
def fail_fast?
configuration.fail_fast
end
def color_enabled?
configuration.color_enabled?(output)
end
def mute_profile_output?(failure_count)
# Don't print out profiled info if there are failures and `--fail-fast` is used, it just clutters the output
!profile_examples? || (fail_fast? && failure_count != 0)
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/text_mate_formatter.rb 0000644 0000041 0000041 00000002200 12261207027 025272 0 ustar www-data www-data require 'cgi'
require 'rspec/core/formatters/html_formatter'
module RSpec
module Core
module Formatters
# Formats backtraces so they're clickable by TextMate
class TextMateFormatter < HtmlFormatter
def backtrace_line(line, skip_textmate_conversion=false)
if skip_textmate_conversion
super(line)
else
format_backtrace_line_for_textmate(super(line))
end
end
def format_backtrace_line_for_textmate(line)
return nil unless line
CGI.escapeHTML(line).sub(/([^:]*\.e?rb):(\d*)/) do
"#{$1}:#{$2} "
end
end
def extra_failure_content(exception)
require 'rspec/core/formatters/snippet_extractor'
backtrace = exception.backtrace.map {|line| backtrace_line(line, :skip_textmate_conversion)}
backtrace.compact!
@snippet_extractor ||= SnippetExtractor.new
" #{@snippet_extractor.snippet(backtrace)}
"
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/progress_formatter.rb 0000644 0000041 0000041 00000001137 12261207027 025154 0 ustar www-data www-data require 'rspec/core/formatters/base_text_formatter'
module RSpec
module Core
module Formatters
class ProgressFormatter < BaseTextFormatter
def example_passed(example)
super(example)
output.print success_color('.')
end
def example_pending(example)
super(example)
output.print pending_color('*')
end
def example_failed(example)
super(example)
output.print failure_color('F')
end
def start_dump
super()
output.puts
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/helpers.rb 0000644 0000041 0000041 00000006666 12261207027 022703 0 ustar www-data www-data module RSpec
module Core
module BacktraceFormatter
extend self
def format_backtrace(backtrace, options = {})
return "" unless backtrace
return backtrace if options[:full_backtrace] == true
if at_exit_index = backtrace.index(RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE)
backtrace = backtrace[0, at_exit_index]
end
cleansed = backtrace.map { |line| backtrace_line(line) }.compact
cleansed.empty? ? backtrace : cleansed
end
protected
def backtrace_line(line)
return nil if RSpec.configuration.backtrace_cleaner.exclude?(line)
RSpec::Core::Metadata::relative_path(line)
rescue SecurityError
nil
end
end
module Formatters
module Helpers
include BacktraceFormatter
SUB_SECOND_PRECISION = 5
DEFAULT_PRECISION = 2
# @api private
#
# Formats seconds into a human-readable string.
#
# @param [Float, Fixnum] duration in seconds
# @return [String] human-readable time
#
# @example
# format_duration(1) #=> "1 minute 1 second"
# format_duration(135.14) #=> "2 minutes 15.14 seconds"
def format_duration(duration)
precision = case
when duration < 1; SUB_SECOND_PRECISION
when duration < 120; DEFAULT_PRECISION
when duration < 300; 1
else 0
end
if duration > 60
minutes = (duration.to_i / 60).to_i
seconds = duration - minutes * 60
"#{pluralize(minutes, 'minute')} #{pluralize(format_seconds(seconds, precision), 'second')}"
else
pluralize(format_seconds(duration, precision), 'second')
end
end
# @api private
#
# Formats seconds to have 5 digits of precision with trailing zeros removed if the number
# is less than 1 or with 2 digits of precision if the number is greater than zero.
#
# @param [Float] float
# @return [String] formatted float
#
# @example
# format_seconds(0.000006) #=> "0.00001"
# format_seconds(0.020000) #=> "0.02"
# format_seconds(1.00000000001) #=> "1"
#
# The precision used is set in {Helpers::SUB_SECOND_PRECISION} and {Helpers::DEFAULT_PRECISION}.
#
# @see #strip_trailing_zeroes
def format_seconds(float, precision = nil)
precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
formatted = sprintf("%.#{precision}f", float)
strip_trailing_zeroes(formatted)
end
# @api private
#
# Remove trailing zeros from a string.
#
# @param [String] string string with trailing zeros
# @return [String] string with trailing zeros removed
def strip_trailing_zeroes(string)
stripped = string.sub(/[^1-9]+$/, '')
stripped.empty? ? "0" : stripped
end
# @api private
#
# Pluralize a word based on a count.
#
# @param [Fixnum] count number of objects
# @param [String] string word to be pluralized
# @return [String] pluralized word
def pluralize(count, string)
"#{count} #{string}#{'s' unless count.to_f == 1}"
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/json_formatter.rb 0000644 0000041 0000041 00000004052 12261207027 024260 0 ustar www-data www-data require 'rspec/core/formatters/base_formatter'
require 'json'
module RSpec
module Core
module Formatters
class JsonFormatter < BaseFormatter
attr_reader :output_hash
def initialize(output)
super
@output_hash = {}
end
def message(message)
(@output_hash[:messages] ||= []) << message
end
def dump_summary(duration, example_count, failure_count, pending_count)
super(duration, example_count, failure_count, pending_count)
@output_hash[:summary] = {
:duration => duration,
:example_count => example_count,
:failure_count => failure_count,
:pending_count => pending_count
}
@output_hash[:summary_line] = summary_line(example_count, failure_count, pending_count)
end
def summary_line(example_count, failure_count, pending_count)
summary = pluralize(example_count, "example")
summary << ", " << pluralize(failure_count, "failure")
summary << ", #{pending_count} pending" if pending_count > 0
summary
end
def stop
super
@output_hash[:examples] = examples.map do |example|
{
:description => example.description,
:full_description => example.full_description,
:status => example.execution_result[:status],
# :example_group,
# :execution_result,
:file_path => example.metadata[:file_path],
:line_number => example.metadata[:line_number],
}.tap do |hash|
if e=example.exception
hash[:exception] = {
:class => e.class.name,
:message => e.message,
:backtrace => e.backtrace,
}
end
end
end
end
def close
output.write @output_hash.to_json
output.close if IO === output && output != $stdout
end
end
end
end
end
rspec-core-2.14.7/lib/rspec/core/formatters/html_printer.rb 0000644 0000041 0000041 00000026732 12261207027 023744 0 ustar www-data www-data require 'erb'
module RSpec
module Core
module Formatters
class HtmlPrinter
include ERB::Util # for the #h method
def initialize(output)
@output = output
end
def print_html_start
@output.puts HTML_HEADER
@output.puts REPORT_HEADER
end
def print_example_group_end
@output.puts " "
@output.puts ""
end
def print_example_group_start( group_id, description, number_of_parents )
@output.puts ""
@output.puts "
"
@output.puts " - #{h(description)}
"
end
def print_example_passed( description, run_time )
formatted_run_time = sprintf("%.5f", run_time)
@output.puts " - #{h(description)}#{formatted_run_time}s
"
end
def print_example_failed( pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace = false )
formatted_run_time = sprintf("%.5f", run_time)
@output.puts " - "
@output.puts " #{h(description)}"
@output.puts " #{formatted_run_time}s"
@output.puts "
"
if exception
@output.puts "
#{h(exception[:message])}
"
if escape_backtrace
@output.puts "
#{h exception[:backtrace]}
"
else
@output.puts "
"
end
end
@output.puts extra_content if extra_content
@output.puts "
"
@output.puts " "
end
def print_example_pending( description, pending_message )
@output.puts " - #{h(description)} (PENDING: #{h(pending_message)})
"
end
def print_summary( was_dry_run, duration, example_count, failure_count, pending_count )
# TODO - kill dry_run?
if was_dry_run
totals = "This was a dry-run"
else
totals = "#{example_count} example#{'s' unless example_count == 1}, "
totals << "#{failure_count} failure#{'s' unless failure_count == 1}"
totals << ", #{pending_count} pending" if pending_count > 0
end
formatted_duration = sprintf("%.5f", duration)
@output.puts ""
@output.puts ""
@output.puts "
"
@output.puts ""
@output.puts "