testament 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .rvmrc
2
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in test_timer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jack Christensen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Testament
2
+
3
+ Note: readme driven development is being used -- not everything below will work yet!
4
+
5
+ NOT READY FOR PRODUCTION USE
6
+
7
+ Testament is a tool to track the cost of running tests.
8
+
9
+ ## Installation
10
+
11
+ $ gem install testament
12
+
13
+ ## Usage
14
+
15
+ To track the time it takes to run your specs, run them like this every time:
16
+
17
+ $ testament record rspec spec/
18
+
19
+ If you have your default rake task set to run your whole test suite, then you can do this:
20
+
21
+ $ testament record rake
22
+
23
+ You may want to create an alias to rake and rspec to run it with testament track automatically.
24
+
25
+ ## Seeing Trends
26
+
27
+ To view some stats, run this:
28
+
29
+ $ testament stats
30
+
31
+ in your project folder.
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/testament ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require 'testament/csv_repository'
3
+
4
+ command = ARGV[1..-1].join(' ')
5
+
6
+ start_time = Time.now
7
+ system command
8
+ end_time = Time.now
9
+
10
+ Testament::CSVRepository.new('testament.log').store command, start_time, end_time
@@ -0,0 +1,27 @@
1
+ require 'csv'
2
+
3
+ module Testament
4
+ class CSVRepository
5
+ attr_reader :file_name
6
+
7
+ def initialize(file_name)
8
+ @file_name = file_name
9
+ end
10
+
11
+ def store(command, start_time, end_time)
12
+ ensure_file_exists
13
+
14
+ CSV.open(file_name, 'ab') do |csv|
15
+ csv << [command, start_time, end_time]
16
+ end
17
+ end
18
+
19
+ private
20
+ def ensure_file_exists
21
+ return if File.exist?(file_name)
22
+ CSV.open(file_name, 'wb') do |csv|
23
+ csv << %w[command start_time end_time]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Testament
2
+ VERSION = "0.0.1"
3
+ end
data/lib/testament.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "testament/version"
2
+
3
+ module Testament
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,60 @@
1
+ require 'rspec'
2
+ require 'fileutils'
3
+ require 'testament/csv_repository'
4
+
5
+ describe Testament::CSVRepository do
6
+ before do
7
+ FileUtils.rm_f file_path
8
+ end
9
+
10
+ subject(:repository) { Testament::CSVRepository.new file_path }
11
+
12
+ let(:file_path) do
13
+ 'spec/tmp/csv.log'
14
+ end
15
+
16
+ describe 'store' do
17
+ let(:command) { 'foo' }
18
+ let(:start_time) { Time.local(2012,1,1, 13,0,0) }
19
+ let(:end_time) { Time.local(2012,1,1, 13,0,1) }
20
+
21
+ def rows
22
+ CSV.read file_path
23
+ end
24
+
25
+ context 'when file does not exist' do
26
+ before do
27
+ repository.store command, start_time, end_time
28
+ end
29
+
30
+ it 'creates the file' do
31
+ expect(File.exist?(file_path)).to be_true
32
+ end
33
+
34
+ it 'writes the CSV header' do
35
+ expect(rows.first).to eq(%w[command start_time end_time])
36
+ end
37
+
38
+ it 'writes the record to the file' do
39
+ expect(rows.size).to eq(2)
40
+ actual_command, actual_start_time, actual_end_time = rows.last
41
+ actual_start_time = Time.parse(actual_start_time)
42
+ actual_end_time = Time.parse(actual_end_time)
43
+ expect(actual_command).to eq(command)
44
+ expect(actual_start_time).to eq(start_time)
45
+ expect(actual_end_time).to eq(end_time)
46
+ end
47
+ end
48
+
49
+ context 'when the file already exists' do
50
+ before do
51
+ repository.store command, start_time, end_time
52
+ repository.store command, start_time, end_time
53
+ end
54
+
55
+ it 'appends the record to the file' do
56
+ expect(rows.size).to eq(3)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,32 @@
1
+ require 'rspec'
2
+ require 'pry'
3
+ require 'time' # for Time.parse
4
+
5
+ RSpec.configure do |config|
6
+ def testament(args="")
7
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ bin = File.expand_path(File.join(File.dirname(__FILE__), '..', 'bin', 'testament'))
9
+ `ruby -I #{lib} #{bin} #{args}`
10
+ end
11
+ end
12
+
13
+ describe 'testament' do
14
+ context 'record' do
15
+ it 'execute it\'s argument' do
16
+ result = testament('record echo foo')
17
+ expect(result).to eq("foo\n")
18
+ end
19
+
20
+ it 'records the execution of the command' do
21
+ testament('record echo foo')
22
+ last_line = `tail -n 1 testament.log`
23
+ command, start_time, end_time = last_line.split(",")
24
+ expect(command).to eq('echo foo')
25
+
26
+ start_time = Time.parse(start_time) rescue nil
27
+ expect(start_time).to be
28
+ end_time = Time.parse(end_time) rescue nil
29
+ expect(end_time).to be
30
+ end
31
+ end
32
+ end
data/testament.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'testament/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "testament"
8
+ gem.version = Testament::VERSION
9
+ gem.authors = ["Jack Christensen"]
10
+ gem.email = ["jack@jackchristensen.com"]
11
+ gem.description = %q{Time, record, and analyze test runs}
12
+ gem.summary = %q{Time, record, and analyze test runs}
13
+ gem.homepage = "https://github.com/JackC/testament"
14
+
15
+ gem.add_development_dependency 'rspec', '>= 2.11.0'
16
+ gem.add_development_dependency 'pry'
17
+
18
+ gem.files = `git ls-files`.split($/)
19
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ["lib"]
22
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testament
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jack Christensen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.11.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.11.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: pry
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Time, record, and analyze test runs
47
+ email:
48
+ - jack@jackchristensen.com
49
+ executables:
50
+ - testament
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bin/testament
61
+ - lib/testament.rb
62
+ - lib/testament/csv_repository.rb
63
+ - lib/testament/version.rb
64
+ - spec/testament/csv_repository_spec.rb
65
+ - spec/testament_spec.rb
66
+ - testament.gemspec
67
+ homepage: https://github.com/JackC/testament
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.23
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Time, record, and analyze test runs
91
+ test_files:
92
+ - spec/testament/csv_repository_spec.rb
93
+ - spec/testament_spec.rb