Class: Houcho::Spec
- Inherits:
-
Element
show all
- Defined in:
- lib/houcho/spec.rb,
lib/houcho/spec/runner.rb
Defined Under Namespace
Classes: Runner
Instance Method Summary
collapse
Methods inherited from Element
#detach, #detach_from_all, #details, #id, #list
Constructor Details
#initialize ⇒ Spec
Returns a new instance of Spec.
9
10
11
12
|
# File 'lib/houcho/spec.rb', line 9
def initialize
super("serverspec")
@specdir = Houcho::Config::SPECDIR
end
|
Instance Method Details
#attach(specs, roles) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/houcho/spec.rb', line 24
def attach(specs, roles)
specs = [specs] unless specs.is_a?(Array)
roles = [roles] unless roles.is_a?(Array)
files = check_existence(specs)
super(files, roles)
end
|
#check_existence(specs) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/houcho/spec.rb', line 15
def check_existence(specs)
specs = [specs] unless specs.is_a?(Array)
files = specs.partition { |spec| File.exist?("#{@specdir}/#{spec}_spec.rb") }
raise SpecFileException, "No such spec file - #{files[1].join(",")}" unless files[1].empty?
files[0]
end
|
#delete(specs, force = false) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/houcho/spec.rb', line 44
def delete(specs, force = false)
specs = [specs] unless specs.is_a?(Array)
detach_from_all(specs) if force
@db.transaction do
specs.each do |spec|
begin
@db.execute("DELETE FROM #{@type} WHERE name = ?", spec)
rescue SQLite3::ConstraintException, "foreign key constraint failed"
raise SpecFileException, "spec file has been attached to role - #{spec}"
end
end
end
begin
check_existence(specs).each do |spec|
File.delete("#{@specdir}/#{spec}_spec.rb")
end
rescue => e
raise e.class, "#{e.message}" unless force
end
end
|
#delete!(specs, force = true) ⇒ Object
71
72
73
|
# File 'lib/houcho/spec.rb', line 71
def delete!(specs, force = true)
delete(specs, true)
end
|
#rename(from, to) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/houcho/spec.rb', line 33
def rename(from, to)
if File.exist?("#{@specdir}/#{to}_spec.rb")
raise SpecFileException, "spec file already exist - #{to}"
end
check_existence(from)
File.rename("#{@specdir}/#{from}_spec.rb", "#{@specdir}/#{to}_spec.rb")
@db.execute("UPDATE #{@type} SET name = ? WHERE name = ?", to, from)
end
|