command-unit 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmNiYmM2MjU5Y2M4ZGY0ZTU4ZTgwNDYyMmUxMDgxNTIxMDJiZmM1NQ==
4
+ MGZkZDc0ZWNmMGYyODczMDBjMTNlN2YzYjhmMTk1NjQxMDA5ZGQ2Yg==
5
5
  data.tar.gz: !binary |-
6
- MWMyZTc3N2FjNWMxZjcwMzNlNWI4YWU5ZjNkMDc5ZTFjM2U2M2UyMQ==
6
+ ZTlhYmIzYmFlNzg3YTkyOThlMzA3NTU3NDRlNzhmNGQ3OTc1NDhjOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDRhZGRkMDM0N2RhNzU3ZTRlZmQ3YjU1OTAwZmQxMmU0NmExOTFlMjc4NjUy
10
- ODhjYjYyMmJhYjVmMjQ5Y2I1MjBkMWRhMjU3ZDgzYzA3MWY3MTI5MDkxMzI0
11
- M2RhYjkyYjE5YjMxODk0NTZhMTQ3MTFkNTA1Nzc5YzAwNjY3ZTU=
9
+ NGM2ZjE2OTEyYzgzYmQxMjJiNjU5MWY3YWNlYmY4NjlmNDZhODEyN2IxOTk2
10
+ OGI2ZWY5Mzc5ZWQ2ZmVjZmM0Zjg4MjliNGVhM2YzOTYwYTYzYWY1NDA4ZTI5
11
+ NmFlMWJiYjYyZGY3ZGZhYjliOGM4MDcxYmY0NzE3ZWFlYWMzMjQ=
12
12
  data.tar.gz: !binary |-
13
- NjVlODMyMmEwMDUzZTljZjA5Y2FjMzVmZmE0Y2FiMWZmMDhjODllYTUxZDU5
14
- NzVjN2YxNDkzNzhjOWE2ODY3ZjA5MzcyYjdmMWE5NTQ3ZThmMTM3NzMxOTc2
15
- M2QxNzgzN2JjZDJlMjZkYzcyMDYzNzBkNDNiMTM4YWExZmE5NWE=
13
+ YzNhZDlkMmRhNzkwZTFiZGFhN2Q0YWM0YWVjODk4YTE5Yjg1YmM3Y2Q5ZjQ3
14
+ YTYzMzczZWUyMjI1YzdhNmMwMzQyYTVhNjQzNzUzMmEyZGYwYjIxYjZlYjk0
15
+ MTUzZGE0YWJlYTU0NTQ0YTdiMTcxOGYwYzI5NjM3MmEzY2RmNzA=
data/README.md CHANGED
@@ -11,7 +11,52 @@ Written in Ruby, designed to test command line apps, whether they're written in
11
11
  Tests are written in Command Unit itself, so no need for any external dependencies yet. I might make this a fundamental requirement of future development, but I'll see how far the project can go on basic Ruby first.
12
12
 
13
13
  ## This is alpha software
14
- So far I've only tested this on Ruby 1.9.3, others may work but I'm not considering support on any other platforms until I've got a stable/useful release out.
14
+ So far I've only tested this on Ruby 1.9.3, others may work but I'm not considering support on any other platforms until I've got a stable/useful release out. The code itself is very rough-and ready, and could benefit from quite a lot of refactoring, especially in [scenario.rb](/samsalisbury/command-unit/blob/master/lib/command-unit/scenario.rb).
15
+
16
+ ## Features
17
+ - No dependencies apart from Ruby itself
18
+ - Assertion helpers (these need work)
19
+ - Clear, readable, colour console output
20
+ - All command-unit tests written using command-unit itself
21
+ - Expectations require a description, making test more useful as documentation
22
+ - Hooks, you can inject your own code easily to respond to tests running/passing/failing.
23
+ -
24
+
25
+ ## Minimalist usage example
26
+ ```ruby
27
+ require 'command-unit'
28
+ include CommandUnit
29
+ scenario 'Writing tests in Command Unit' do
30
+
31
+ when_i 'do something wacky' do |context|
32
+ context[:data] = 'call a method or something here'
33
+ end
34
+
35
+ i_expect "to receive a string containing 'or' do |context|
36
+ expect context[:data], &contains('or')
37
+ end
38
+
39
+ i_expect "the string to exactly equal 'or'" do |context|
40
+ expect context[:data], &is_equal_to('or')
41
+ end
42
+
43
+ end
44
+
45
+ run
46
+ ```
47
+ Output:
48
+ ```
49
+ Running 1 scenarios...
50
+
51
+ Running scenario 1: Writing tests in Command Unit
52
+ When I do something wacky
53
+ I expect to receive a string containing 'or'...Success!
54
+ I expect the string to exactly equal 'or'...Failure!
55
+ Expecting exactly 'or', but got 'call a method or something here'
56
+ Scenario 1 finished, 1 tests, 2 expectations with 1 successful and 1 failures.
57
+
58
+ Ran 1 scenarios, 0 passed, 1 failed (tests passed: 0, failed: 1) (expectations passed: 1, failed: 1)
59
+ ```
15
60
 
16
61
  ## Installation
17
62
  `gem install command-unit`
@@ -19,5 +64,12 @@ So far I've only tested this on Ruby 1.9.3, others may work but I'm not consider
19
64
  ## Development
20
65
  Unpack the gem with `gem unpack command-unit`
21
66
  Run tests:
22
- $ cd command-unit-0.0.1
23
- $ ruby test/test.rb
67
+ ```
68
+ $ cd command-unit-0.0.3
69
+ $ ruby test/test.rb
70
+ ```
71
+
72
+ ## More?
73
+ This is fairly experimental, and I know a lot of people probably won't like it, or will think it needless (why not just use rspec?!), but it satisfies a need I have right now, and I'm happy so far.
74
+
75
+ I'd really love to hear any constructive criticism on both the code and the conventions in test-writing that command-unit enforces, you can email me at samsalisbury@gmail.com
data/changelog.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # Command Unit changelog
2
2
 
3
- - 0.0.2 lots of changes:
3
+ - 0.0.3 2013-08-18
4
+ * Expectation helpers
5
+ - These need to be rethought, as they require too manu ugly ampersands in the tests
6
+ - 0.0.2 2013-08-18
4
7
  * More useful output:
5
8
  - Colours
6
9
  - Totals
7
10
  * Namespaces to help with splitting up tests
8
11
  * More self-tests
9
- - 0.0.1 some basic assertions
10
- - 0.0.0 initial release
12
+ - 0.0.1 2013-08-17
13
+ * some basic assertions
14
+ - 0.0.0 2013-08-17
15
+ * initial release, nothing much useful yet
data/command-unit.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "command-unit"
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.author = "Samuel R. Salisbury"
6
6
  s.email = "samsalisbury@gmail.com"
@@ -0,0 +1,20 @@
1
+ require_relative '../lib/command-unit'
2
+ include CommandUnit
3
+
4
+ scenario 'Writing tests in Command Unit' do
5
+
6
+ when_i 'do something wacky' do |context|
7
+ context[:data] = 'call a method or something here'
8
+ end
9
+
10
+ i_expect "to receive a string containing 'or'" do |context|
11
+ expect context[:data], &contains('or')
12
+ end
13
+
14
+ i_expect "the string to exactly equal 'or'" do |context|
15
+ expect context[:data], &is_equal_to('or')
16
+ end
17
+
18
+ end
19
+
20
+ run
data/lib/command-unit.rb CHANGED
@@ -4,6 +4,7 @@ require_relative 'command-unit/test'
4
4
  require_relative 'command-unit/expectation'
5
5
  require_relative 'command-unit/expectation_result'
6
6
  require_relative 'command-unit/hooks'
7
+ require_relative 'command-unit/expectation_helpers'
7
8
 
8
9
  module CommandUnit
9
10
 
@@ -101,12 +102,4 @@ module CommandUnit
101
102
  @@current_scenario.current_test.add_expectation Expectation.new(desc, &i_expect_block)
102
103
  end
103
104
 
104
- def pass(desc = '')
105
- ExpectationResult.new(desc, true)
106
- end
107
-
108
- def fail(desc = '')
109
- ExpectationResult.new(desc, false)
110
- end
111
-
112
105
  end
@@ -0,0 +1,52 @@
1
+ module CommandUnit
2
+
3
+ def pass(desc = '')
4
+ ExpectationResult.new(desc, true)
5
+ end
6
+
7
+ def fail(desc = '')
8
+ ExpectationResult.new(desc, false)
9
+ end
10
+
11
+ def expect(thing, &proc)
12
+ if proc.nil?
13
+ if thing == true
14
+ return ExpectationResult.new('', true)
15
+ elsif thing == false
16
+ return ExpectationResult.new('Expected true but was false.', false)
17
+ else
18
+ raise "CommandUnit::expect requires either true, false or any other value with a Proc"
19
+ end
20
+ end
21
+
22
+ result = proc.call(thing)
23
+ if result.is_a? Array
24
+ return ExpectationResult.new(result[1], result[0])
25
+ else
26
+ return ExpectationResult.new('', result)
27
+ end
28
+ end
29
+
30
+ def is_equal_to(this_thing)
31
+ return Proc.new do |other_thing|
32
+ if other_thing == this_thing
33
+ true
34
+ else
35
+ [false, "Expecting exactly '#{this_thing}', but got '#{other_thing}'"]
36
+ end
37
+ end
38
+ end
39
+
40
+ def contains(this_thing)
41
+ return Proc.new do |collection|
42
+ if not collection.respond_to? :include?
43
+ [false, "Unable to test if '#{collection}' contains '#{this_thing}' as it has no include? method."]
44
+ elsif collection.include? this_thing
45
+ true
46
+ else
47
+ [false, "Expected '#{collection}' to contain '#{this_thing}'."]
48
+ end
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,123 @@
1
+ include CommandUnit
2
+
3
+ def expect_passing(result)
4
+ if not result.is_a? ExpectationResult
5
+ fail 'Expecting an ExpectationResult'
6
+ elsif result.success? != true
7
+ fail 'Expecting a pass'
8
+ else
9
+ pass
10
+ end
11
+ end
12
+
13
+ def expect_failing(result)
14
+ if not result.is_a? ExpectationResult
15
+ fail 'Expecting an ExpectationResult'
16
+ elsif result.success? != false
17
+ fail 'Expecting a failure'
18
+ else
19
+ pass
20
+ end
21
+ end
22
+
23
+ def expect_failing_with_message(result, expected_message)
24
+ if not result.is_a? ExpectationResult
25
+ fail 'Expecting an ExpectationResult'
26
+ elsif result.success? != false
27
+ fail 'Expecting a failure'
28
+ elsif result.message != expected_message
29
+ fail "Expecting failure message '#{expected_message}', but got '#{result.message}'"
30
+ else
31
+ pass
32
+ end
33
+ end
34
+
35
+ scenario :command_unit, 'Using expectation helpers' do
36
+
37
+ when_i 'use the expect helper with a boolean true' do |context|
38
+ context[:result] = expect true
39
+ end
40
+
41
+ i_expect 'to get a passing result' do |context|
42
+ expect_passing context[:result]
43
+ end
44
+
45
+ when_i 'use the expect helper with a boolean false' do |context|
46
+ context[:result] = expect false
47
+ end
48
+
49
+ i_expect 'to get a failing result' do |context|
50
+ expect_failing context[:result]
51
+ end
52
+
53
+ i_expect 'to get a failing result with message saying "Expected true but was false."' do |context|
54
+ expect_failing_with_message context[:result], 'Expected true but was false.'
55
+ end
56
+
57
+ when_i 'use the expect helper with a value and a Proc returning true' do |context|
58
+ context[:result] = expect 'anything' do
59
+ true
60
+ end
61
+ end
62
+
63
+ i_expect 'to get a passing result' do |context|
64
+ expect_passing context[:result]
65
+ end
66
+
67
+ when_i 'use the expect helper with a value and a Proc returning false' do |context|
68
+ context[:result] = expect 'anything' do
69
+ false
70
+ end
71
+ end
72
+
73
+ i_expect 'to get a failing result' do |context|
74
+ expect_failing context[:result]
75
+ end
76
+
77
+ when_i 'use the expect helper with a value and a Proc returning false and a message' do |context|
78
+ context[:result] = expect 'anything' do
79
+ [false, 'Failure message']
80
+ end
81
+ end
82
+
83
+ i_expect 'to get a failing result' do |context|
84
+ expect_failing_with_message context[:result], 'Failure message'
85
+ end
86
+
87
+ when_i 'use the expect helper with is_equal_to and the things are equal' do |context|
88
+ context[:result] = expect(123, &is_equal_to(123))
89
+ end
90
+
91
+ i_expect 'to get a passing result' do |context|
92
+ expect_passing context[:result]
93
+ end
94
+
95
+ when_i 'use the expect helper with is_equal_to and the things are not equal' do |context|
96
+ context[:result] = expect('my random string', &is_equal_to('my unequal string'))
97
+ end
98
+
99
+ i_expect 'to get a failing result' do |context|
100
+ expect_failing context[:result]
101
+ end
102
+
103
+ when_i 'use the expect helper with contains returns true when one string contains another' do |context|
104
+ context[:result] = expect "This is a string.", &contains('is a st')
105
+ end
106
+
107
+ i_expect 'to get a passing result' do |context|
108
+ expect_passing context[:result]
109
+ end
110
+
111
+ when_i 'use the expect helper with contains returns true when one string does not contain another' do |context|
112
+ context[:result] = expect "This is a string.", &contains('pancreas')
113
+ end
114
+
115
+ i_expect 'to get a failing result' do |context|
116
+ expect_failing context[:result]
117
+ end
118
+
119
+ i_expect 'to get a failing result with message saying "Expected \'This is a string.\' to contain \'pancreas\'."' do |context|
120
+ expect_failing_with_message context[:result], "Expected 'This is a string.' to contain 'pancreas'."
121
+ end
122
+
123
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command-unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel R. Salisbury
@@ -22,8 +22,10 @@ files:
22
22
  - README.md
23
23
  - changelog.md
24
24
  - command-unit.gemspec
25
+ - examples/minimal_scenario.rb
25
26
  - lib/command-unit.rb
26
27
  - lib/command-unit/expectation.rb
28
+ - lib/command-unit/expectation_helpers.rb
27
29
  - lib/command-unit/expectation_result.rb
28
30
  - lib/command-unit/hooks
29
31
  - lib/command-unit/hooks.rb
@@ -33,6 +35,7 @@ files:
33
35
  - lib/string/console_colours.rb
34
36
  - test/quick-test.rb
35
37
  - test/scenarios/empty_scenario.rb
38
+ - test/scenarios/expectation_helper_tests.rb
36
39
  - test/scenarios/one_test_one_failing_expectation.rb
37
40
  - test/scenarios/one_test_one_passing_expectation.rb
38
41
  - test/test.rb