Skip to content

Commit

Permalink
Merge pull request #49 from rspec/rspec-4-compatibility
Browse files Browse the repository at this point in the history
Adjust specs for RSpec 4 compatibility
  • Loading branch information
pirj committed Mar 7, 2021
2 parents eec25d8 + 8a2bdcc commit 45afc97
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 103 deletions.
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--format documentation
--color
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source 'https://rubygems.org'

gemspec

%w[rspec rspec-core rspec-expectations rspec-mocks].each do |lib|
%w[rspec rspec-support rspec-core rspec-expectations rspec-mocks].each do |lib|
library_path = File.expand_path("../../#{lib}", __FILE__)
if File.exist?(library_path) && !ENV['USE_GIT_REPOS']
gem lib, :path => library_path
Expand All @@ -12,9 +12,6 @@ gemspec
end
end

# only the main branch is supported on rspec-support
gem "rspec-support", :git => "git://github.com/rspec/rspec-support.git"

gem "aruba"

if RUBY_VERSION < '1.9.3'
Expand Down
52 changes: 6 additions & 46 deletions spec/rspec/collection_matchers/have_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'stringio'

describe "have matcher" do
RSpec.describe "have matcher" do
let(:inflector) do
Class.new do
def self.pluralize(string)
Expand Down Expand Up @@ -560,14 +560,12 @@ def players

module RSpec
module CollectionMatchers
describe Syntax do
RSpec.describe Syntax do
describe "expression generation" do
let(:target) { "foo" }
let(:expectation) { "eq('bar')" }
let(:positive_expect_example) { "expect(foo).to eq('bar')" }
let(:positive_should_example) { "foo.should eq('bar')" }
let(:negative_expect_example) { "expect(foo).not_to eq('bar')" }
let(:negative_should_example) { "foo.should_not eq('bar')" }

def positive_expression
Syntax.positive_expression(target, expectation)
Expand All @@ -577,52 +575,14 @@ def negative_expression
Syntax.negative_expression(target, expectation)
end

context "when only :expect is enabled", :uses_only_expect do
before do
expect(Expectations::Syntax.should_enabled?).to be_falsey
expect(Expectations::Syntax.expect_enabled?).to be_truthy
end

it 'generates a positive expression using the expect syntax' do
expect(positive_expression).to eq(positive_expect_example)
end

it 'generates a negative expression using the expect syntax' do
expect(negative_expression).to eq(negative_expect_example)
end
it 'generates a positive expression using the expect syntax' do
expect(positive_expression).to eq(positive_expect_example)
end

context "when both :should and :expect are enabled", :uses_should do
before do
expect(Expectations::Syntax.should_enabled?).to be_truthy
expect(Expectations::Syntax.expect_enabled?).to be_truthy
end

it 'generates a positive expression using the expect syntax' do
expect(positive_expression).to eq(positive_expect_example)
end

it 'generates a negative expression using the expect syntax' do
expect(negative_expression).to eq(negative_expect_example)
end
end

context "when only :should is enabled", :uses_only_should do
before do
Expectations::Syntax.should_enabled?.should be_truthy
Expectations::Syntax.expect_enabled?.should be_falsey
end

it 'generates a positive expression using the expect syntax' do
positive_expression.should eq(positive_should_example)
end

it 'generates a negative expression using the expect syntax' do
negative_expression.should eq(negative_should_example)
end
it 'generates a negative expression using the expect syntax' do
expect(negative_expression).to eq(negative_expect_example)
end
end

end
end
end
2 changes: 1 addition & 1 deletion spec/rspec/collection_matchers/rails_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'active_model'

module RSpec::CollectionMatchers
describe "Have extensions for rails" do
RSpec.describe "Have extensions for rails" do
describe "error_on" do
it "provides a description including the name of what the error is on" do
expect(have(1).error_on(:whatever).description).to eq "have 1 error on :whatever"
Expand Down
52 changes: 2 additions & 50 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,8 @@
Dir['./spec/support/**/*'].each {|f| require f}

RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true if RSpec::Expectations::Version::STRING < "3.0"
config.run_all_when_everything_filtered = true
config.filter_run :focus

config.order = 'random'

config.expect_with :rspec do |rspec|
rspec.syntax = :expect
end

config.mock_with :rspec do |rspec|
rspec.syntax = :expect
end
end

shared_context "with #should enabled", :uses_should do
orig_syntax = nil

before(:all) do
orig_syntax = RSpec::Matchers.configuration.syntax
RSpec::Matchers.configuration.syntax = [:expect, :should]
end

after(:all) do
RSpec::Matchers.configuration.syntax = orig_syntax
end
end

shared_context "with #should exclusively enabled", :uses_only_should do
orig_syntax = nil

before(:all) do
orig_syntax = RSpec::Matchers.configuration.syntax
RSpec::Matchers.configuration.syntax = :should
end

after(:all) do
RSpec::Matchers.configuration.syntax = orig_syntax
end
end

shared_context "with #expect exclusively enabled", :uses_only_expect do
orig_syntax = nil

before(:all) do
orig_syntax = RSpec::Matchers.configuration.syntax
RSpec::Matchers.configuration.syntax = :expect
end

after(:all) do
RSpec::Matchers.configuration.syntax = orig_syntax
end
config.expect_with :rspec
config.mock_with :rspec
end
2 changes: 1 addition & 1 deletion spec/support/shared_examples.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_examples_for "an RSpec matcher" do |options|
RSpec.shared_examples_for "an RSpec matcher" do |options|
let(:valid_value) { options.fetch(:valid_value) }
let(:invalid_value) { options.fetch(:invalid_value) }

Expand Down

0 comments on commit 45afc97

Please sign in to comment.