Class: NUnit

Inherits:
Object
  • Object
show all
Defined in:
lib/nunitr/nunit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNUnit

Returns a new instance of NUnit.



7
8
9
10
11
# File 'lib/nunitr/nunit.rb', line 7

def initialize()
  @teamcity_nunit_version = 'v4.0 x86 NUnit-2.5.3'
  @nuget_nunit_version = '2.6.0.12051'
  @nuget_path = './.nuget/NuGet.exe'       
end

Instance Attribute Details

#nuget_nunit_versionObject

Returns the value of attribute nuget_nunit_version.



5
6
7
# File 'lib/nunitr/nunit.rb', line 5

def nuget_nunit_version
  @nuget_nunit_version
end

#nuget_pathObject

Returns the value of attribute nuget_path.



5
6
7
# File 'lib/nunitr/nunit.rb', line 5

def nuget_path
  @nuget_path
end

#teamcity_nunit_versionObject

Returns the value of attribute teamcity_nunit_version.



5
6
7
# File 'lib/nunitr/nunit.rb', line 5

def teamcity_nunit_version
  @teamcity_nunit_version
end

Instance Method Details

#run(pattern, environment = nil) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nunitr/nunit.rb', line 13

def run(pattern, environment=nil)
  glob_pattern = "**/[b][i][n]/Release/#{pattern}.dll"
  dlls = Dir.glob(glob_pattern)
  raise TestFilesNotFound, "No tests found for pattern #{glob_pattern}" if dlls.empty?

  if !environment.nil?
    dlls.each do |dll| 
      config = File.dirname(dll) + "/App.#{environment}.config"
      raise ConfigFileNotFound, "Config file #{config} not found" if !File.exists?(config)
      sh "copy #{config} #{dll + '.config'}".gsub('/', '\\') 
    end 
  end

  sh "#{runner} #{dlls.join(' ').strip}"   
end

#runnerObject



29
30
31
32
33
34
35
36
# File 'lib/nunitr/nunit.rb', line 29

def runner
  if ENV['teamcity.dotnet.nunitlauncher'].nil?
    sh "#{@nuget_path} install Nunit.Runners -o ./tools -Version #{@nuget_nunit_version}"
    return Dir.glob("./tools/*#{@nuget_nunit_version}/**/nunit-console.exe").last
  end
  
  return "#{ENV['teamcity.dotnet.nunitlauncher']} #{@teamcity_nunit_version}"
end