Class: Bob::Test::AbstractRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/bob/test/repo.rb

Direct Known Subclasses

GitRepo, SvnRepo

Instance Method Summary collapse

Constructor Details

#initialize(name = "test_repo") ⇒ AbstractRepo

Returns a new instance of AbstractRepo.



3
4
5
# File 'lib/bob/test/repo.rb', line 3

def initialize(name = "test_repo")
  @path = Bob.directory.join(name)
end

Instance Method Details

#add_commit(message) ⇒ Object



14
15
16
17
18
19
# File 'lib/bob/test/repo.rb', line 14

def add_commit(message)
  Dir.chdir(@path) {
    yield
    commit(message)
  }
end

#add_failing_commitObject



29
30
31
32
33
34
35
# File 'lib/bob/test/repo.rb', line 29

def add_failing_commit
  add_commit("This commit will fail") {
    system "echo '#{script(1)}' > test"
    system "chmod +x test"
    add    "test"
  }
end

#add_successful_commitObject



21
22
23
24
25
26
27
# File 'lib/bob/test/repo.rb', line 21

def add_successful_commit
  add_commit("This commit will work") {
    `echo '#{script(0)}' > test`
    `chmod +x test`
    add "test"
  }
end

#commandObject



45
46
47
# File 'lib/bob/test/repo.rb', line 45

def command
  "./test"
end

#createObject



7
8
9
10
11
12
# File 'lib/bob/test/repo.rb', line 7

def create
  add_commit("First commit") {
    `echo 'just a test repo' >> README`
    add "README"
  }
end

#headObject



37
38
39
# File 'lib/bob/test/repo.rb', line 37

def head
  commits.last["id"]
end

#script(status) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/bob/test/repo.rb', line 49

def script(status)
  <<SH
#!/bin/sh
echo "Running tests..."
exit #{status}
SH
end

#short_headObject



41
42
43
# File 'lib/bob/test/repo.rb', line 41

def short_head
  head[0..6]
end