Class: AbilityAnalysis::SpecGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ability_analysis/spec_generator.rb

Overview

Originally used to generate an overwhelmingly large spec file. Kept primarily for reference

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ability_analysis, output: $stdout) ⇒ SpecGenerator

Returns a new instance of SpecGenerator.


8
9
10
11
# File 'lib/ability_analysis/spec_generator.rb', line 8

def initialize(ability_analysis, output: $stdout)
  @ability_analysis = ability_analysis
  @output = output
end

Instance Attribute Details

#ability_analysisObject (readonly)

Returns the value of attribute ability_analysis.


6
7
8
# File 'lib/ability_analysis/spec_generator.rb', line 6

def ability_analysis
  @ability_analysis
end

Instance Method Details

#generateObject

rubocop:todo Metrics/MethodLength


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
# File 'lib/ability_analysis/spec_generator.rb', line 15

def generate # rubocop:todo Metrics/MethodLength
  output <<~HEADER
    # frozen_string_literal: true

    require 'cancan/matchers'

    RSpec.describe #{ability} do

      subject(:ability) { described_class.new(user) }

      let(:user) { nil }

  HEADER
  generate_permissions_list('global_permissions', sorted_permissions)
  generate_shared_example
  generate_no_user
  output
  generate_basic_user
  output
  roles.each do |role|
    generate_for(role)
    output
  end
  output 'end'
  output
end