Class: Transpec::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/transpec/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = Dir.pwd) ⇒ Project

Returns a new instance of Project.



10
11
12
# File 'lib/transpec/project.rb', line 10

def initialize(path = Dir.pwd)
  @path = path
end

Instance Attribute Details

#path ⇒ Object (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/transpec/project.rb', line 8

def path
  @path
end

Instance Method Details

#basename ⇒ Object



14
15
16
# File 'lib/transpec/project.rb', line 14

def basename
  File.basename(path)
end

#depend_on_rspec_rails? ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
# File 'lib/transpec/project.rb', line 22

def depend_on_rspec_rails?
  return @depend_on_rspec_rails if instance_variable_defined?(:@depend_on_rspec_rails)
  return @depend_on_rspec_rails = false unless using_bundler?

  require 'bundler'
  gemfile_lock_content = File.read(gemfile_lock_path)
  lockfile = Bundler::LockfileParser.new(gemfile_lock_content)
  @depend_on_rspec_rails = lockfile.specs.any? { |gem| gem.name == 'rspec-rails' }
end

#rspec_version ⇒ Object



32
33
34
# File 'lib/transpec/project.rb', line 32

def rspec_version
  @rspec_version ||= RSpecVersion.new(fetch_rspec_version)
end

#using_bundler? ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/transpec/project.rb', line 18

def using_bundler?
  File.exist?(gemfile_lock_path)
end

#with_bundler_clean_env ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/transpec/project.rb', line 36

def with_bundler_clean_env
  if defined?(Bundler) && using_bundler?
    Bundler.with_clean_env do
      # Bundler.with_clean_env cleans environment variables
      # which are set after bundler is loaded.
      yield
    end
  else
    yield
  end
end