Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow `RSpec::Matchers` to be mixed into `main`. #428

Merged
merged 1 commit into from

1 participant

@myronmarston

I don't understand why the references to the other
constant was breaking this, but it was :(.

Fixes #427.

@myronmarston myronmarston Allow `RSpec::Matchers` to be mixed into `main`.
I don't understand why the references to the other
constant was breaking this, but it was :(.

Fixes #427.
78b8e79
@myronmarston myronmarston merged commit 98996ef into from
@myronmarston myronmarston deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 17, 2014
  1. @myronmarston

    Allow `RSpec::Matchers` to be mixed into `main`.

    myronmarston authored
    I don't understand why the references to the other
    constant was breaking this, but it was :(.
    
    Fixes #427.
This page is out of date. Refresh to see the latest.
View
7 lib/rspec/matchers.rb
@@ -840,11 +840,14 @@ def yield_successive_args(*args)
private
+ BE_PREDICATE_REGEX = /^(be_(?:an?_)?)(.*)/
+ HAS_REGEX = /^(?:have_)(.*)/
+
def method_missing(method, *args, &block)
case method.to_s
- when BuiltIn::BePredicate::REGEX
+ when BE_PREDICATE_REGEX
BuiltIn::BePredicate.new(method, *args, &block)
- when BuiltIn::Has::REGEX
+ when HAS_REGEX
BuiltIn::Has.new(method, *args, &block)
else
super
View
4 lib/rspec/matchers/built_in/be.rb
@@ -192,10 +192,8 @@ def parse_expected(expected)
expected
end
- REGEX = /^(be_(?:an?_)?)(.*)/
-
def prefix_and_expected(symbol)
- REGEX.match(symbol.to_s).captures.compact
+ Matchers::BE_PREDICATE_REGEX.match(symbol.to_s).captures.compact
end
def prefix_to_sentence
View
4 lib/rspec/matchers/built_in/has.rb
@@ -26,10 +26,8 @@ def description
private
- REGEX = /^(?:have_)(.*)/
-
def predicate
- @predicate ||= :"has_#{@method_name.to_s.match(REGEX).captures.first}?"
+ @predicate ||= :"has_#{@method_name.to_s.match(Matchers::HAS_REGEX).captures.first}?"
end
def method_description
View
19 spec/rspec/matchers_spec.rb
@@ -1,5 +1,24 @@
require 'spec_helper'
+main = self
+describe RSpec::Matchers do
+ include ::RSpec::Support::InSubProcess
+
+ it 'can be mixed into `main`' do
+ in_sub_process do
+ main.instance_eval do
+ include RSpec::Matchers
+ expect(3).to eq(3)
+ expect(3).to be_odd
+
+ expect {
+ expect(4).to be_zero
+ }.to fail_with("expected zero? to return true, got false")
+ end
+ end
+ end
+end
+
module RSpec
module Matchers
describe "built in matchers" do
Something went wrong with that request. Please try again.