Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into attribute_defined_statically-hash
  • Loading branch information
bquorning committed Sep 16, 2018
2 parents 5d32135 + 23d870a commit 9ff194a
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/context_wording.rb
Expand Up @@ -56,6 +56,7 @@ def message
def joined_prefixes
quoted = prefixes.map { |prefix| "'#{prefix}'" }
return quoted.first if quoted.size == 1

quoted << "or #{quoted.pop}"
quoted.join(', ')
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/cop.rb
Expand Up @@ -79,6 +79,7 @@ def all_cops_config

def rspec_pattern_config?
return unless all_cops_config.key?('RSpec')

all_cops_config.fetch('RSpec').key?('Patterns')
end

Expand Down
Expand Up @@ -73,6 +73,7 @@ class AttributeDefinedStatically < Cop
def on_block(node)
factory_attributes(node).to_a.flatten.each do |attribute|
next if proc?(attribute) || association?(attribute)

add_offense(attribute, location: :expression)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/factory_bot/create_list.rb
Expand Up @@ -139,6 +139,7 @@ def format_method_call(node, method, arguments)

def format_receiver(receiver)
return '' unless receiver

"#{receiver.source}."
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/implicit_subject.rb
Expand Up @@ -57,6 +57,7 @@ def autocorrect(node)

def valid_usage?(node)
return false unless style == :single_line_only

example = node.ancestors.find { |parent| example?(parent) }
example && example.single_line?
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/let_before_examples.rb
Expand Up @@ -72,6 +72,7 @@ def check_let_declarations(node)

node.each_child_node do |child|
next if child.sibling_index < first_example.sibling_index

add_offense(child, location: :expression) if let?(child)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/overwriting_setup.rb
Expand Up @@ -58,6 +58,7 @@ def find_duplicates(node)

def common_setup?(node)
return false unless setup?(node)

# Search only for setup with basic_literal arguments (e.g. :sym, :str)
# or no arguments at all.
node.send_node.arguments.all?(&:basic_literal?)
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/rspec/predicate_matcher.rb
Expand Up @@ -145,6 +145,7 @@ def check_explicit(node) # rubocop:disable Metrics/MethodLength
end

return if part_of_ignored_node?(node)

predicate_matcher?(node) do |_actual, matcher|
add_offense(
node,
Expand Down Expand Up @@ -337,6 +338,7 @@ def args_loc(send_node)
def block_loc(send_node)
parent = send_node.parent
return unless parent.block_type?

range_between(
send_node.loc.expression.end_pos,
parent.loc.expression.end_pos
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/rails/http_status.rb
Expand Up @@ -41,6 +41,7 @@ def on_send(node)
http_status(node) do |ast_node|
checker = checker_class.new(ast_node)
return unless checker.offensive?

add_offense(checker.node, message: checker.message)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/scattered_let.rb
Expand Up @@ -43,6 +43,7 @@ def check_let_declarations(body)
first_let = lets.first
lets.each_with_index do |node, idx|
next if node.sibling_index == first_let.sibling_index + idx

add_offense(node, location: :expression)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/subject_stub.rb
Expand Up @@ -72,6 +72,7 @@ class SubjectStub < Cop

def expectation?(node)
return if all_matcher?(node)

receive_message?(node)
end

Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/cop/rspec/void_expect.rb
Expand Up @@ -25,18 +25,21 @@ class VoidExpect < Cop

def on_send(node)
return unless expect?(node)

check_expect(node)
end

def on_block(node)
return unless expect_block?(node)

check_expect(node)
end

private

def check_expect(node)
return unless void?(node)

add_offense(node, location: :expression)
end

Expand Down
4 changes: 4 additions & 0 deletions tasks/cops_documentation.rake
Expand Up @@ -156,6 +156,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
cop.to_s.start_with?('RuboCop::Cop::RSpec')
end
return if selected_cops.empty?

content = "# #{department}\n".dup
selected_cops.each do |cop|
content << print_cop_with_doc(cop, config)
Expand Down Expand Up @@ -195,6 +196,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
cop.to_s.start_with?('RuboCop::Cop::RSpec')
end
return if selected_cops.empty?

type_title = department[0].upcase + department[1..-1]
filename = "cops_#{department.downcase}.md"
content = "#### Department [#{type_title}](#{filename})\n\n".dup
Expand Down Expand Up @@ -259,8 +261,10 @@ task documentation_syntax_check: :yard_for_generate_documentation do
cops = RuboCop::Cop::Cop.registry
cops.each do |cop|
next unless %i[RSpec Capybara FactoryBot].include?(cop.department)

examples = YARD::Registry.all(:class).find do |code_object|
next unless RuboCop::Cop::Badge.for(code_object.to_s) == cop.badge

break code_object.tags('example')
end

Expand Down

0 comments on commit 9ff194a

Please sign in to comment.