Skip to content

Commit

Permalink
Expose files to support testing Cops using RSpec (rubocop#3179)
Browse files Browse the repository at this point in the history
The exposed files can be loaded from spec_helper using:

    require 'rubocop/rspec/support'
  • Loading branch information
tjwp authored and Neodelf committed Oct 15, 2016
1 parent 5dcaa5d commit 1dcf4bf
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [#3173](https://github.com/bbatsov/rubocop/pull/3173): Make `Style/ModuleFunction` configurable with `module_function` and `extend_self` styles. ([@tjwp][])
* [#3105](https://github.com/bbatsov/rubocop/issues/3105): Add new `Style/RequestReferer` cop. ([@giannileggio][])
* [#3200](https://github.com/bbatsov/rubocop/pull/3200): Add autocorrect for `Style/EachForSimpleLoop` cop. ([@tejasbubane][])
* [#3179](https://github.com/bbatsov/rubocop/pull/3179): Expose files to support testings Cops using RSpec. ([@tjwp][])

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require 'tempfile'

# This module provides methods that make it easier to test Cops.
module CopHelper
extend RSpec::SharedContext

Expand Down Expand Up @@ -64,6 +65,8 @@ def _investigate(cop, processed_source)

module RuboCop
module Cop
# Monkey-patch Cop for tests to provide easy access to messages and
# highlights.
class Cop
def messages
offenses.sort.map(&:message)
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions lib/rubocop/rspec/support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# encoding: utf-8
# frozen_string_literal: true

# Require this file to load code that supports testing using RSpec.

require 'rubocop/rspec/cop_helper'
require 'rubocop/rspec/host_environment_simulation_helper'
require 'rubocop/rspec/shared_contexts'
require 'rubocop/rspec/shared_examples'
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

require 'webmock/rspec'

# Require supporting files exposed for testing.
require 'rubocop/rspec/support'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
Expand Down

0 comments on commit 1dcf4bf

Please sign in to comment.