File: rails_application_with_shoulda_context.rb

package info (click to toggle)
ruby-shoulda-context 2.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 476 kB
  • sloc: ruby: 1,712; sh: 200; makefile: 4
file content (46 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download | duplicates (2)
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
require_relative "snowglobe"

class RailsApplicationWithShouldaContext < Snowglobe::RailsApplication
  ROOT_DIRECTORY = Pathname.new("../../..").expand_path(__FILE__)

  def create
    super

    bundle.updating do
      bundle.add_gem(test_framework_gem_name, group: :test)
      bundle.add_gem("shoulda-context", path: ROOT_DIRECTORY, group: :test)
    end
  end

  def test_framework_require_path
    if TEST_FRAMEWORK == "test_unit"
      "test-unit"
    else
      "minitest/autorun"
    end
  end

  def create_gem_with_macro(module_name:, location:, macro_name:)
    fs.write_file("#{location}/shoulda_macros/macros.rb", <<~FILE)
      module #{module_name}
        def #{macro_name}
          puts "#{macro_name} is available"
        end
      end

      Shoulda::Context.configure do |config|
        config.extend(#{module_name})
      end
    FILE
  end

  private

  def test_framework_gem_name
    if TEST_FRAMEWORK == "test_unit"
      "test-unit"
    else
      "minitest"
    end
  end
end