Skip to content

Commit

Permalink
Move Mocha.configure & .configuration -> mocha/configuration.rb
Browse files Browse the repository at this point in the history
This seems like a better home and makes the require statements more
intention-revealing/explicit.
  • Loading branch information
floehopper committed Nov 23, 2019
1 parent 730528a commit 50cc0b4
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 40 deletions.
1 change: 0 additions & 1 deletion .yardopts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
--template-path yard-templates
--no-private
lib/mocha.rb
lib/mocha/api.rb
lib/mocha/hooks.rb
lib/mocha/mock.rb
Expand Down
27 changes: 0 additions & 27 deletions lib/mocha.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
require 'mocha/version'
require 'mocha/configuration'

module Mocha
# Allows setting of configuration options. See {Configuration} for the available options.
#
# Typically the configuration is set globally in a +test_helper.rb+ or +spec_helper.rb+ file.
#
# @see Configuration
#
# @yieldparam configuration [Configuration] the configuration for modification
#
# @example Setting multiple configuration options
# Mocha.configure do |c|
# c.stubbing_method_unnecessarily = :prevent
# c.stubbing_method_on_non_mock_object = :warn
# c.stubbing_method_on_nil = :allow
# end
#
def self.configure
yield configuration
end

# @private
def self.configuration
Configuration.configuration
end
end
24 changes: 24 additions & 0 deletions lib/mocha/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
module Mocha
# Allows setting of configuration options. See {Configuration} for the available options.
#
# Typically the configuration is set globally in a +test_helper.rb+ or +spec_helper.rb+ file.
#
# @see Configuration
#
# @yieldparam configuration [Configuration] the configuration for modification
#
# @example Setting multiple configuration options
# Mocha.configure do |c|
# c.stubbing_method_unnecessarily = :prevent
# c.stubbing_method_on_non_mock_object = :warn
# c.stubbing_method_on_nil = :allow
# end
#
def self.configure
yield configuration
end

# @private
def self.configuration
Configuration.configuration
end

# This class provides a number of ways to configure the library.
#
# Typically the configuration is set globally in a +test_helper.rb+ or +spec_helper.rb+ file.
Expand Down
2 changes: 1 addition & 1 deletion lib/mocha/expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require 'mocha/in_state_ordering_constraint'
require 'mocha/change_state_side_effect'
require 'mocha/cardinality'
require 'mocha'
require 'mocha/configuration'

module Mocha
# Methods on expectations returned from {Mock#expects}, {Mock#stubs}, {ObjectMethods#expects} and {ObjectMethods#stubs}.
Expand Down
2 changes: 1 addition & 1 deletion lib/mocha/mockery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'mocha/receivers'
require 'mocha/state_machine'
require 'mocha/logger'
require 'mocha'
require 'mocha/configuration'
require 'mocha/stubbing_error'
require 'mocha/not_initialized_error'
require 'mocha/expectation_error_factory'
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/stubbing_method_unnecessarily_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'
require 'mocha/configuration'

class StubbingMethodUnnecessarilyTest < Mocha::TestCase
include AcceptanceTest
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/stubbing_nil_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'
require 'mocha/configuration'

class StubbingNilTest < Mocha::TestCase
include AcceptanceTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'
require 'mocha/configuration'

class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
include AcceptanceTest
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/stubbing_non_existent_class_method_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'
require 'mocha/configuration'

class StubbingNonExistentClassMethodTest < Mocha::TestCase
include AcceptanceTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'
require 'mocha/configuration'

class StubbingNonExistentInstanceMethodTest < Mocha::TestCase
include AcceptanceTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'
require 'mocha/configuration'

class StubbingNonPublicAnyInstanceMethodTest < Mocha::TestCase
include AcceptanceTest
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/stubbing_non_public_class_method_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'
require 'mocha/configuration'

class StubbingNonPublicClassMethodTest < Mocha::TestCase
include AcceptanceTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'
require 'mocha/configuration'

class StubbingNonPublicInstanceMethodTest < Mocha::TestCase
include AcceptanceTest
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/stubbing_on_non_mock_object_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'
require 'mocha/configuration'

class StubbingOnNonMockObjectTest < Mocha::TestCase
include AcceptanceTest
Expand Down
1 change: 0 additions & 1 deletion test/unit/configuration_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require File.expand_path('../../test_helper', __FILE__)
require 'mocha'
require 'mocha/configuration'

class ConfigurationTest < Mocha::TestCase
Expand Down

0 comments on commit 50cc0b4

Please sign in to comment.