summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb
blob: 4876fcd50503cd8f72b708ec2bf92328c1292d93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

require 'fast_spec_helper'

require 'rubocop'
require 'rubocop/rspec/support'

require_relative '../../../../rubocop/cop/qa/ambiguous_page_object_name'

RSpec.describe RuboCop::Cop::QA::AmbiguousPageObjectName do
  include CopHelper

  let(:source_file) { 'qa/page.rb' }

  subject(:cop) { described_class.new }

  context 'in a QA file' do
    before do
      allow(cop).to receive(:in_qa_file?).and_return(true)
    end

    it "registers an offense for pages named `page`" do
      expect_offense(<<-RUBY)
      Page::Layout::Bar.perform do |page|
                                    ^^^^ Don't use 'page' as a name for a Page Object. Use `bar` instead.
        expect(page).to have_performance_bar
        expect(page).to have_detailed_metrics
      end
      RUBY
    end

    it "doesnt offend if the page object is named otherwise" do
      expect_no_offenses(<<-RUBY)
        Page::Object.perform do |obj|
          obj.whatever
        end
      RUBY
    end
  end

  context 'outside of a QA file' do
    before do
      allow(cop).to receive(:in_qa_file?).and_return(false)
    end

    it "does not register an offense" do
      expect_no_offenses(<<-RUBY)
        Page::Object.perform do |page|
          page.do_something
        end
      RUBY
    end
  end
end