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.



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

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#basenameObject



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

def basename
  File.basename(@path)
end

#require_bundler?Boolean

Returns:

  • (Boolean)


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

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

#rspec_versionObject



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

def rspec_version
  @rspec_version ||= begin
    command = 'rspec --version'
    command = 'bundle exec ' + command if require_bundler?

    version_string = nil

    Dir.chdir(@path) do
      with_bundler_clean_env { version_string = `#{command}`.chomp }
    end

    RSpecVersion.new(version_string)
  end
end

#with_bundler_clean_envObject



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

def with_bundler_clean_env
  if defined?(Bundler) && require_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