lib/rubocop/cop/rspec/named_subject.rb in rubocop-rspec-2.0.0.pre vs lib/rubocop/cop/rspec/named_subject.rb in rubocop-rspec-2.0.0

- old
+ new

@@ -40,27 +40,23 @@ # subject(:user) { described_class.new } # # it { is_expected.to be_valid } # end class NamedSubject < Base - MSG = 'Name your test subject if you need '\ - 'to reference it explicitly.' + MSG = 'Name your test subject if you need to reference it explicitly.' - def_node_matcher :rspec_block?, <<-PATTERN - { - #{Examples::ALL.block_pattern} - #{Hooks::ALL.block_pattern} - } - PATTERN + def_node_matcher :example_or_hook_block?, + block_pattern('{#Examples.all #Hooks.all}') - def_node_matcher :shared_example?, <<-PATTERN - #{SharedGroups::EXAMPLES.block_pattern} - PATTERN + def_node_matcher :shared_example?, + block_pattern('#SharedGroups.examples') def_node_search :subject_usage, '$(send nil? :subject)' def on_block(node) - return if !rspec_block?(node) || ignored_shared_example?(node) + if !example_or_hook_block?(node) || ignored_shared_example?(node) + return + end subject_usage(node) do |subject_node| add_offense(subject_node.loc.selector) end end