Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Commit

Permalink
refactoring + more lib/OneSelf.rb tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed May 24, 2015
1 parent 8d1684c commit b3531d7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 38 deletions.
13 changes: 5 additions & 8 deletions lib/Git.rb
Expand Up @@ -3,7 +3,7 @@ class Git

def method_missing(cmd,*args)
path,options = args[0],args[1]
options = quoted(options) if ['add','rm'].include?(cmd.to_s)
options = single_quoted(options) if ['add','rm'].include?(cmd.to_s)
Dir.chdir(path) do
git_cmd = stderr2stdout("git #{cmd} #{options}")
log << git_cmd
Expand All @@ -22,17 +22,14 @@ def log
private

include Cleaner

def stderr2stdout(cmd)
cmd + ' ' + '2>&1'
end
include Stderr2Stdout

def success
0
end

def quoted(args)
"'" + args + "'"
def single_quoted(s)
"'" + s + "'"
end

end
33 changes: 9 additions & 24 deletions lib/OneSelf.rb
Expand Up @@ -14,7 +14,10 @@ def created(hash)
data = {
'objectTags' => [ 'cyber-dojo' ],
'actionTags' => [ 'create' ],
'location' => { 'lat' => hash[:latitude], 'long' => hash[:longtitude] },
'location' => {
'lat' => hash[:latitude],
'long' => hash[:longtitude]
},
'properties' => {
'dojo-id' => hash[:kata_id],
'language-name' => hash[:language_name],
Expand Down Expand Up @@ -45,6 +48,8 @@ def started(avatar)
# - - - - - - - - - - - - - - - - - - - - - -

def tested(avatar,hash)
# tags belonging to 1self are camelCase
# tags belonging to me (in properties) are dash-separated
data = {
'objectTags' => [ 'cyber-dojo' ],
'actionTags' => [ 'test-run' ],
Expand Down Expand Up @@ -107,32 +112,12 @@ def stream_id
'GSYZNQSYANLMWEEH'
end

def read_token
'474f621260b2f9e5b6f6025cd5eea836b362b0bf1bfa'
end
#def read_token
# '474f621260b2f9e5b6f6025cd5eea836b362b0bf1bfa'
#end

def write_token
'ddbc8384eaf4b6f0e70d66b606ccbf7ad4bb22bfe113'
end

end

#------------------------------------------------
# tags belonging to 1self are camelCase
# tags belonging to me (in properties) are dash-separated
#
# data = {
# 'objectTags' => [ 'cyber-dojo' ],
# 'actionTags' => [ 'test-run' ],
# 'dateTime' => Time.mktime(*now).utc.iso8601.to_s,
# 'properties' => {
# 'dojo-id' => avatar.kata.id,
# 'avatar' => avatar.name,
# 'tag' => tag,
# 'color' => css(colour),
# 'added-line-count' => added_line_count,
# 'deleted-line-count' => deleted_line_count,
# 'seconds-since-last-test' => secs.to_i,
# }
# }
#------------------------------------------------
2 changes: 1 addition & 1 deletion lib/Stderr2Stdout.rb
Expand Up @@ -2,7 +2,7 @@
module Stderr2Stdout # mixin

def stderr2stdout(cmd)
cmd + ' 2>&1'
cmd + ' ' + '2>&1'
end

end
2 changes: 2 additions & 0 deletions lib/all.rb
@@ -1,4 +1,6 @@

# this list has order dependencies

%w{
Stderr2Stdout
Cleaner
Expand Down
19 changes: 14 additions & 5 deletions test/lib/one_self_test.rb
Expand Up @@ -56,7 +56,7 @@ def setup

# - - - - - - - - - - - - - - - - -

test 'created' do
test 'kata created' do
http_requester = OneSelfHttpRequesterStub.new
one_self = OneSelf.new(disk, http_requester)
kata = make_kata
Expand All @@ -75,7 +75,7 @@ def setup

# - - - - - - - - - - - - - - - - -

test 'started' do
test 'avatar started' do
kata = make_kata
lion = kata.start_avatar(['lion'])
http_requester = OneSelfHttpRequesterStub.new
Expand All @@ -93,7 +93,16 @@ def setup

# - - - - - - - - - - - - - - - - -

test 'tested' do
test 'tests run' do
light_colour('red', '#F00')
light_colour('amber','#FF0')
light_colour('green','#0F0')
light_colour('timed_out','#C0C0C0')
end

# - - - - - - - - - - - - - - - - -

def light_colour(colour,css)
kata = make_kata
lion = kata.start_avatar(['lion'])
http_requester = OneSelfHttpRequesterStub.new
Expand All @@ -102,7 +111,7 @@ def setup
disk[lion.path].write(one_self.manifest_filename, started_manifest)
hash = {
:tag => 1,
:colour => 'red',
:colour => colour,
:now => Time.now,
:added_line_count => 2,
:deleted_line_count => 6,
Expand All @@ -117,7 +126,7 @@ def setup
assert_equal kata.id, properties['dojo-id']
assert_equal 'lion', properties['avatar']
assert_equal hash[:tag], properties['tag']
assert_equal '#F00', properties['color']
assert_equal css, properties['color']
assert_equal hash[:added_line_count], properties['added-line-count']
assert_equal hash[:deleted_line_count], properties['deleted-line-count']
assert_equal hash[:seconds_since_last_test], properties['seconds-since-last-test']
Expand Down

0 comments on commit b3531d7

Please sign in to comment.