Skip to content

Commit

Permalink
cleaner scoping
Browse files Browse the repository at this point in the history
- def classes/modules in RSpec::Rails::Matchers instead of
  RSpec::Matchers
- less opening classes/more includuing modules
  • Loading branch information
dchelimsky committed Nov 22, 2011
1 parent ffd6c07 commit 5af9d7d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 deletions.
1 change: 1 addition & 0 deletions lib/rspec/rails/example/rails_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module RailsExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::SetupAndTeardownAdapter
include RSpec::Rails::TestUnitAssertionAdapter
include RSpec::Rails::Matchers
end
end
end
4 changes: 2 additions & 2 deletions lib/rspec/rails/matchers/be_a_new.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module RSpec::Matchers
module RSpec::Rails::Matchers
class BeANew
include BaseMatcher
include RSpec::Matchers::BaseMatcher

# @api private
def matches?(actual)
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/rails/matchers/be_new_record.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module RSpec::Matchers
module RSpec::Rails::Matchers
class BeANewRecord
include BaseMatcher
include RSpec::Matchers::BaseMatcher

# @api private
def matches?(actual)
Expand Down
46 changes: 26 additions & 20 deletions lib/rspec/rails/matchers/have_extension.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
require 'active_support/core_ext/module/aliasing'
require 'rspec/matchers/have'

module RSpec
module Matchers
class Have
# @api private
#
# Enhances the failure message for `should have(n)` matchers
def failure_message_for_should_with_errors_on_extensions
return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@actual}" if @collection_name == :errors_on
return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@actual}" if @collection_name == :error_on
return failure_message_for_should_without_errors_on_extensions
end
alias_method_chain :failure_message_for_should, :errors_on_extensions
module RSpec::Rails::Matchers
module HaveExtensions
extend ActiveSupport::Concern

# @api private
#
# Enhances the failure message for `should have(n)` matchers
def failure_message_for_should_with_errors_on_extensions
return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@actual}" if @collection_name == :errors_on
return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@actual}" if @collection_name == :error_on
return failure_message_for_should_without_errors_on_extensions
end

# @api private
#
# Enhances the description for `should have(n)` matchers
def description_with_errors_on_extensions
return "have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
return "have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}" if @collection_name == :error_on
return description_without_errors_on_extensions
end
# @api private
#
# Enhances the description for `should have(n)` matchers
def description_with_errors_on_extensions
return "have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
return "have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}" if @collection_name == :error_on
return description_without_errors_on_extensions
end

included do
alias_method_chain :failure_message_for_should, :errors_on_extensions
alias_method_chain :description, :errors_on_extensions
end
end
end

RSpec::Matchers::Have.class_eval do
include RSpec::Rails::Matchers::HaveExtensions
end
1 change: 1 addition & 0 deletions lib/rspec/rails/matchers/match_unless_raises.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module RSpec::Rails::Matchers
module MatchUnlessRaises
# @api private
attr_accessor :rescued_exception

# @api private
Expand Down
2 changes: 2 additions & 0 deletions spec/rspec/rails/matchers/be_a_new_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "spec_helper"

describe "be_a_new matcher" do
include RSpec::Rails::Matchers

context "new record" do
let(:record) do
Class.new do
Expand Down
2 changes: 2 additions & 0 deletions spec/rspec/rails/matchers/be_new_record_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "spec_helper"

describe "be_new_record" do
include RSpec::Rails::Matchers

context "un-persisted record" do
it "passes" do
record = double('record', :persisted? => false)
Expand Down

0 comments on commit 5af9d7d

Please sign in to comment.