command-unit 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Njk2YmM5MjE0MTgzYjlhMGZlZDdhOTNlZWMzMWZlN2I2YjdhNzk4ZA==
5
+ data.tar.gz: !binary |-
6
+ YjdiNzVmYzE3MzFiYmQyMzIwNWQ3ZmZlYzk3M2ZkODE5NTE0MjVmNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MDQ4ZTIzZjQ5MjdjMTdlYmU1MjUwYjIwZWFlZTBjNmM1MjUzYjc3Mjk0MTQ2
10
+ MmZjMzg4YTA3MTYyNDg0N2NiNzZhOGI5N2IxZTQ1OTI0NjNmMzBjODU1OTY1
11
+ ODM5MTFiZjBlYjZhMDZiZWJkNjgwMWE2ZDdmYzdkZDIwMDE2MWU=
12
+ data.tar.gz: !binary |-
13
+ YWM5ZjU5OGEyZTA3NDQxZTE0YmE1YmQxMTliODhlNmRmOTlkMzdkOWY4NThl
14
+ NWI5OWUwMjU1M2NlN2IxN2M3Y2Q5Mzc2N2U4YzRiMTUyNmM5ZWIzOTA5YWZk
15
+ YjY2ZDljZTRlMGYwNGNkNzgwMDkxNDViNTg0YmZmMjE4Y2ZjYmY=
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p448
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Command Unit
2
+ A very simple test runner, primarily written to support development of [Righteous Git Hooks](http://github.com/samsalisbury/righteous-git-hooks).
@@ -0,0 +1,30 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "command-unit"
3
+ s.version = "0.0.0"
4
+ s.platform = Gem::Platform::RUBY
5
+ s.author = "Samuel R. Salisbury"
6
+ s.email = "samsalisbury@gmail.com"
7
+ s.homepage = "http://github.com/samsalisbury/command-unit"
8
+ s.summary = "ALPHA: Simple test runner for command line tools."
9
+ s.description = "ALPHA: Test runner for one-shot command line tools. This was built to support writing git hooks over at http://github.com/samsalisbury/righteous-git-hooks"
10
+
11
+ s.rubyforge_project = s.name
12
+
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+
15
+ # If you have runtime dependencies, add them here
16
+ # s.add_runtime_dependency "other", "~> 1.2"
17
+
18
+ # If you have development dependencies, add them here
19
+ # s.add_development_dependency "another", "= 0.9"
20
+
21
+ # The list of files to be contained in the gem
22
+ s.files = `git ls-files`.split("\n")
23
+ # s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
24
+ # s.extensions = `git ls-files ext/extconf.rb`.split("\n")
25
+
26
+ s.require_path = 'lib'
27
+
28
+ # For C extensions
29
+ # s.extensions = "ext/extconf.rb"
30
+ end
@@ -0,0 +1,88 @@
1
+ module CommandUnit
2
+
3
+ @@scenarios = []
4
+ @@current_scenario = nil
5
+ attr_reader :current_scenario
6
+
7
+ def scenario(description, &block)
8
+ @@scenarios.push Scenario.new(description, &block)
9
+ end
10
+
11
+ def run
12
+ @@scenarios.each do |scenario|
13
+ scenario.run
14
+ end
15
+ end
16
+
17
+ def set_up(&set_up_block)
18
+ raise 'set_up must be called from inside a scenario block' if @@current_scenario == nil
19
+ @@current_scenario.set_up_block = set_up_block
20
+ end
21
+
22
+ def when_i(desc, &when_i_block)
23
+ raise 'when_i must be called from inside a scenario block' if @@current_scenario == nil
24
+ @@current_scenario.add_test Test.new(desc, &when_i_block)
25
+ end
26
+
27
+ def i_expect(desc, &i_expect_block)
28
+ raise 'i_expect must be called from inside a scenario block' if @@current_scenario == nil
29
+ @@current_scenario.current_test.add_expectation Expectation.new(desc, &i_expect_block)
30
+ end
31
+
32
+ class Scenario
33
+ def initialize(desc, &block)
34
+ @desc = desc
35
+ @block = block
36
+ @set_up_block = nil
37
+ @tests = []
38
+ @current_test = nil
39
+ @tear_down_block = nil
40
+ end
41
+
42
+ def run
43
+ puts "Running scenario: #{@desc}"
44
+ @@current_scenario = self
45
+ @block.call
46
+ @tests.each do |test|
47
+ puts "When I #{test.when_i_text}"
48
+ context = {}
49
+ @set_up_block.call(context) unless @set_up_block.nil?
50
+ test.when_i_block.call(context) unless test.when_i_block.nil?
51
+ print 'I expect '
52
+ test.expectations.each do |expectation|
53
+ puts expectation.desc
54
+ expectation.block.call(context) unless expectation.block.nil?
55
+ end
56
+ end
57
+ @@current_scenario = nil
58
+ end
59
+
60
+ def add_test(test)
61
+ @tests.push test
62
+ @current_test = test
63
+ end
64
+
65
+ attr_accessor :desc, :block, :set_up_block, :tests, :tear_down_block, :current_test
66
+ end
67
+
68
+ class Test
69
+ def initialize(when_i_text, &when_i_block)
70
+ @when_i_text = when_i_text
71
+ @when_i_block = when_i_block
72
+ @expectations = []
73
+ end
74
+ attr_reader :when_i_text, :when_i_block, :expectations
75
+ def add_expectation(expectation)
76
+ @expectations.push expectation
77
+ end
78
+ end
79
+
80
+ class Expectation
81
+ def initialize(expectation_text, &expectaton_block)
82
+ @desc = expectation_text
83
+ @block = expectaton_block
84
+ end
85
+ attr_accessor :desc, :block
86
+ end
87
+
88
+ end
@@ -0,0 +1,23 @@
1
+ include CommandUnit
2
+
3
+ scenario 'When blahblahs are whatnots' do
4
+
5
+ set_up do |context|
6
+ puts 'set_up called!'
7
+ context[:thing] = 'some property set in set_up'
8
+ end
9
+
10
+ when_i "don't do anything" do |context|
11
+ # Doing nothing
12
+ puts 'when_i called!'
13
+ context[:thing2] = 'thing'
14
+ end
15
+
16
+ i_expect 'to see a nice success message' do |context|
17
+ puts 'i_expect called!'
18
+ context[:thing3] = 'thang'
19
+ end
20
+
21
+ end
22
+
23
+ run
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: command-unit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel R. Salisbury
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ! 'ALPHA: Test runner for one-shot command line tools. This was built
14
+ to support writing git hooks over at http://github.com/samsalisbury/righteous-git-hooks'
15
+ email: samsalisbury@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .ruby-version
21
+ - README.md
22
+ - command-unit.gemspec
23
+ - lib/command-unit.rb
24
+ - test/quick-test.rb
25
+ homepage: http://github.com/samsalisbury/command-unit
26
+ licenses: []
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.3.6
42
+ requirements: []
43
+ rubyforge_project: command-unit
44
+ rubygems_version: 2.0.6
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: ! 'ALPHA: Simple test runner for command line tools.'
48
+ test_files: []