Class: Transpec::Project

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

Defined Under Namespace

Classes: GemfileLockNotFoundError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = Dir.pwd) ⇒ Project

Returns a new instance of Project.



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

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#basenameObject



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

def basename
  File.basename(path)
end

#depend_on_rspec_rails?Boolean

Returns:

  • (Boolean)


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

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?
  @depend_on_rspec_rails = dependency_gems.any? { |gem| gem.name == 'rspec-rails' }
end

#rspec_versionObject



30
31
32
# File 'lib/transpec/project.rb', line 30

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

#using_bundler?Boolean

Returns:

  • (Boolean)


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

def using_bundler?
  gemfile_path = File.join(path, 'Gemfile')
  File.exist?(gemfile_path)
end

#with_bundler_clean_envObject



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

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