File: current_bundle.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 (61 lines) | stat: -rw-r--r-- 1,084 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require "bundler"
require "appraisal"

module Tests
  class CurrentBundle
    AppraisalNotSpecified = Class.new(ArgumentError)

    include Singleton

    def assert_appraisal!
      unless appraisal_in_use?
        message = <<MSG


Please run tests starting with `appraisal <appraisal_name>`.
Possible appraisals are: #{available_appraisals}

MSG
        raise AppraisalNotSpecified, message
      end
    end

    def appraisal_in_use?
      path.dirname == root.join("gemfiles")
    end

    def current_or_latest_appraisal
      current_appraisal || latest_appraisal
    end

    def latest_appraisal
      available_appraisals.max
    end

    def current_appraisal
      if appraisal_in_use?
        File.basename(path, ".gemfile")
      end
    end

    private

    def available_appraisals
      appraisals = []

      Appraisal::AppraisalFile.each do |appraisal|
        appraisals << appraisal.name
      end

      appraisals
    end

    def path
      Bundler.default_gemfile
    end

    def root
      Pathname.new("../../..").expand_path(__FILE__)
    end
  end
end