riot 0.11.4 → 0.12.0.pre

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.
Files changed (61) hide show
  1. data/CHANGELOG +6 -0
  2. data/VERSION +1 -1
  3. data/lib/riot/assertion.rb +10 -5
  4. data/lib/riot/assertion_macro.rb +10 -0
  5. data/lib/riot/assertion_macros/any.rb +16 -2
  6. data/lib/riot/assertion_macros/assigns.rb +42 -16
  7. data/lib/riot/assertion_macros/empty.rb +13 -2
  8. data/lib/riot/assertion_macros/equals.rb +17 -2
  9. data/lib/riot/assertion_macros/equivalent_to.rb +15 -1
  10. data/lib/riot/assertion_macros/exists.rb +13 -1
  11. data/lib/riot/assertion_macros/includes.rb +16 -0
  12. data/lib/riot/assertion_macros/kind_of.rb +13 -0
  13. data/lib/riot/assertion_macros/matches.rb +14 -0
  14. data/lib/riot/assertion_macros/nil.rb +10 -0
  15. data/lib/riot/assertion_macros/not_borat.rb +10 -0
  16. data/lib/riot/assertion_macros/raises.rb +28 -0
  17. data/lib/riot/assertion_macros/respond_to.rb +14 -0
  18. data/lib/riot/assertion_macros/same_elements.rb +13 -2
  19. data/lib/riot/assertion_macros/size.rb +12 -0
  20. data/lib/riot/context.rb +4 -126
  21. data/lib/riot/context_helpers.rb +132 -0
  22. data/lib/riot/context_options.rb +24 -0
  23. data/riot.gemspec +46 -27
  24. data/test.watchr +70 -0
  25. data/test/core/assertion_macros/any_test.rb +36 -4
  26. data/test/core/assertion_macros/assigns_test.rb +28 -0
  27. data/test/core/assertion_macros/empty_test.rb +35 -7
  28. data/test/core/assertion_macros/equals_test.rb +29 -0
  29. data/test/core/assertion_macros/equivalent_to_test.rb +36 -17
  30. data/test/core/assertion_macros/exists_test.rb +25 -4
  31. data/test/core/assertion_macros/includes_test.rb +12 -0
  32. data/test/core/assertion_macros/kind_of_test.rb +15 -0
  33. data/test/core/assertion_macros/matches_test.rb +49 -0
  34. data/test/core/assertion_macros/nil_test.rb +10 -8
  35. data/test/core/assertion_macros/not_borat_test.rb +14 -8
  36. data/test/core/assertion_macros/raises_test.rb +39 -6
  37. data/test/core/assertion_macros/respond_to_test.rb +18 -1
  38. data/test/core/assertion_macros/same_elements_test.rb +17 -0
  39. data/test/core/assertion_macros/size_test.rb +45 -5
  40. data/test/core/context/asserts_topic_test.rb +21 -0
  41. data/test/core/context/context_test.rb +35 -0
  42. data/test/core/{context_with_options_test.rb → context/context_with_options_test.rb} +0 -0
  43. data/test/core/context/deny_test.rb +25 -0
  44. data/test/core/context/helper_test.rb +11 -0
  45. data/test/core/context/hookup_test.rb +13 -0
  46. data/test/core/context/nested_contexts_test.rb +40 -0
  47. data/test/core/context/premium_setup_test.rb +19 -0
  48. data/test/core/context/should_test.rb +17 -0
  49. data/test/core/{using_describe_in_a_test.rb → context/using_describe_in_a_test.rb} +9 -0
  50. data/test/core/{chained_context_middleware_test.rb → middleware/chained_context_middleware_test.rb} +0 -0
  51. data/test/core/{context_middleware_test.rb → middleware/context_middleware_test.rb} +0 -0
  52. data/test/core/{assertion_macro_test.rb → runnable/assertion_macro_test.rb} +0 -0
  53. data/test/core/{assertion_test.rb → runnable/assertion_test.rb} +0 -0
  54. data/test/core/{message_test.rb → runnable/message_test.rb} +0 -0
  55. data/test/core/runnable/negative_assertion_test.rb +36 -0
  56. data/test/core/{setup_test.rb → runnable/setup_test.rb} +0 -0
  57. data/test/core/{situation_test.rb → runnable/situation_test.rb} +0 -0
  58. data/test/core/{teardown_test.rb → runnable/teardown_test.rb} +0 -0
  59. metadata +54 -32
  60. data/test/core/assertion_macros/matching_test.rb +0 -24
  61. data/test/core/context_test.rb +0 -157
@@ -0,0 +1,70 @@
1
+ ENV["WATCHR"] = "1"
2
+ system 'clear'
3
+
4
+ def growl(message)
5
+ growlnotify = `which growlnotify`.chomp
6
+ title = "Watchr Test Results"
7
+ image = message.include?('0 failures, 0 errors') ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
8
+ options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
9
+ system %(#{growlnotify} #{options} &)
10
+ end
11
+
12
+ def run(cmd)
13
+ puts(cmd)
14
+ `#{cmd}`
15
+ end
16
+
17
+ def run_test_file(file)
18
+ system('clear')
19
+ result = run(%Q(ruby -I"lib:test" -rubygems #{file}))
20
+ growl result.split("\n").last rescue nil
21
+ puts result
22
+ end
23
+
24
+ def run_all_tests
25
+ system('clear')
26
+ result = run "rake test:all"
27
+ growl result.split("\n").last rescue nil
28
+ puts result
29
+ end
30
+
31
+ def run_all_features
32
+ system('clear')
33
+ run "cucumber"
34
+ end
35
+
36
+ def related_test_files(path)
37
+ Dir['test/**/*.rb'].select { |file| file =~ /#{File.basename(path).split(".").first}_test.rb/ }
38
+ end
39
+
40
+ def run_suite
41
+ run_all_tests
42
+ # run_all_features
43
+ end
44
+
45
+ watch('test/teststrap\.rb') { run_all_tests }
46
+ watch('test/(.*).*_test\.rb') { |m| run_test_file(m[0]) }
47
+ watch('lib/.*/.*\.rb') { |m| related_test_files(m[0]).map {|tf| run_test_file(tf) } }
48
+ # watch('features/.*/.*\.feature') { run_all_features }
49
+
50
+ # Ctrl-\
51
+ Signal.trap 'QUIT' do
52
+ puts " --- Running all tests ---\n\n"
53
+ run_all_tests
54
+ end
55
+
56
+ @interrupted = false
57
+
58
+ # Ctrl-C
59
+ Signal.trap 'INT' do
60
+ if @interrupted then
61
+ @wants_to_quit = true
62
+ abort("\n")
63
+ else
64
+ puts "Interrupt a second time to quit"
65
+ @interrupted = true
66
+ Kernel.sleep 1.5
67
+ # raise Interrupt, nil # let the run loop catch it
68
+ run_suite
69
+ end
70
+ end
@@ -1,10 +1,8 @@
1
1
  require 'teststrap'
2
2
 
3
3
  context "An any assertion macro" do
4
- setup do
5
- def assert_any(string)
6
- Riot::Assertion.new("test") { string }.any
7
- end
4
+ helper(:assert_any) do |o|
5
+ Riot::Assertion.new("test") { o }.any
8
6
  end
9
7
 
10
8
  assertion_test_passes("when an array has items", "is not empty") { assert_any([1]) }
@@ -17,3 +15,37 @@ context "An any assertion macro" do
17
15
  assert_any({})
18
16
  end
19
17
  end
18
+
19
+ context "A negative, any assertion macro" do
20
+ helper(:any) do |o|
21
+ Riot::Assertion.new("test", true) { o }.any
22
+ end
23
+
24
+ asserts(":error when value is nil") do
25
+ any(nil).run(Riot::Situation.new)[0] # No method any? on nil
26
+ end.equals(:error)
27
+
28
+ asserts(":pass when string is empty") do
29
+ any("").run(Riot::Situation.new)
30
+ end.equals([:pass, "has elements"])
31
+
32
+ asserts(":pass when array is empty") do
33
+ any([]).run(Riot::Situation.new)
34
+ end.equals([:pass, "has elements"])
35
+
36
+ asserts(":pass when hash is empty") do
37
+ any({}).run(Riot::Situation.new)
38
+ end.equals([:pass, "has elements"])
39
+
40
+ asserts(":fail when string is empty") do
41
+ any("foo").run(Riot::Situation.new)[0..1]
42
+ end.equals([:fail, %Q{expected "foo" not to have elements}])
43
+
44
+ asserts(":fail when array has elements") do
45
+ any([1,2]).run(Riot::Situation.new)[0..1]
46
+ end.equals([:fail, %Q{expected [1, 2] not to have elements}])
47
+
48
+ asserts(":fail when hash has elements") do
49
+ any({"bar" => "baz"}).run(Riot::Situation.new)[0..1]
50
+ end.equals([:fail, %Q{expected {"bar"=>"baz"} not to have elements}])
51
+ end
@@ -22,3 +22,31 @@ context "An assigns assertion macro" do
22
22
  topic.assigns(:nil_val)
23
23
  end
24
24
  end # An assigns assertion macro
25
+
26
+ context "A negative assigns assertion macro" do
27
+ setup do
28
+ item = Object.new
29
+ item.instance_eval { @foo = 1; @nil_val = nil }
30
+ Riot::Assertion.new("test", true) { item }
31
+ end
32
+
33
+ asserts(":pass when @bar is not defined") do
34
+ topic.assigns(:bar).run(Riot::Situation.new)
35
+ end.equals([:pass, ""])
36
+
37
+ asserts(":pass when @nil_val is actually nil") do
38
+ topic.assigns(:nil_val).run(Riot::Situation.new)
39
+ end.equals([:pass, ""])
40
+
41
+ asserts(":pass when @foo does not equal 2") do
42
+ topic.assigns(:foo, 2).run(Riot::Situation.new)
43
+ end.equals([:pass, ""])
44
+
45
+ asserts(":fail when @foo is defined") do
46
+ topic.assigns(:foo).run(Riot::Situation.new)[0..1]
47
+ end.equals([:fail, "expected :foo to not be assigned a value"])
48
+
49
+ asserts(":fail when @foo does equal 1") do
50
+ topic.assigns(:foo, 1).run(Riot::Situation.new)[0..1]
51
+ end.equals([:fail, "expected :foo to not be equal to 1"])
52
+ end # A negative assigns assertion macro
@@ -1,24 +1,52 @@
1
1
  require 'teststrap'
2
2
 
3
3
  context "An empty assertion macro" do
4
- setup do
5
- def assert_empty(string)
6
- Riot::Assertion.new("test") { string }.empty
7
- end
4
+ helper(:assert_empty) do |o|
5
+ Riot::Assertion.new("test") { o }.empty
8
6
  end
9
7
 
10
- assertion_test_passes("when string is empty") { assert_empty("") }
8
+ assertion_test_passes("when string is empty", "is empty") { assert_empty("") }
11
9
  assertion_test_fails("when string has content", "expected \" \" to be empty") do
12
10
  assert_empty(" ")
13
11
  end
14
12
 
15
- assertion_test_passes("when an array is empty") { assert_empty([]) }
13
+ assertion_test_passes("when an array is empty", "is empty") { assert_empty([]) }
16
14
  assertion_test_fails("when an array has items", "expected [1] to be empty") do
17
15
  assert_empty([1])
18
16
  end
19
17
 
20
- assertion_test_passes("when a hash is empty") { assert_empty({}) }
18
+ assertion_test_passes("when a hash is empty", "is empty") { assert_empty({}) }
21
19
  assertion_test_fails("when a hash has items", "expected {:name=>\"washington\"} to be empty") do
22
20
  assert_empty({:name => 'washington'})
23
21
  end
24
22
  end
23
+
24
+ context "A negative empty assertion macro" do
25
+ helper(:assert_empty) do |o|
26
+ Riot::Assertion.new("test", true) { o }.empty.run(Riot::Situation.new)
27
+ end
28
+
29
+ asserts("when string is not empty") do
30
+ assert_empty("foo")
31
+ end.equals([:pass, "is empty"])
32
+
33
+ asserts("when string is empty") do
34
+ assert_empty("")[0..1]
35
+ end.equals([:fail, "expected \"\" to not be empty"])
36
+
37
+ asserts("when array is not empty") do
38
+ assert_empty([1])
39
+ end.equals([:pass, "is empty"])
40
+
41
+ asserts("when array is empty") do
42
+ assert_empty([])[0..1]
43
+ end.equals([:fail, "expected [] to not be empty"])
44
+
45
+ asserts("when hash is not empty") do
46
+ assert_empty({:boo => "blux"})
47
+ end.equals([:pass, "is empty"])
48
+
49
+ asserts("when hash is empty") do
50
+ assert_empty({})[0..1]
51
+ end.equals([:fail, "expected {} to not be empty"])
52
+ end # A negative empty assertion macro
@@ -40,3 +40,32 @@ context "An equals assertion macro" do
40
40
  end # with block as the expectation
41
41
 
42
42
  end # An equals assertion macro
43
+
44
+ context "A negative equals assertion macro" do
45
+ setup do
46
+ Riot::Assertion.new("that flirgy", true) { "foo" }
47
+ end
48
+
49
+ asserts(":pass when values do not match") do
50
+ topic.equals("bar").run(Riot::Situation.new) == [:pass, %Q{is equal to "bar" when it is "foo"}]
51
+ end
52
+
53
+ asserts(":fail when values do match") do
54
+ topic.equals("foo").run(Riot::Situation.new)[0..1] == [:fail, %Q{did not expect "foo"}]
55
+ end
56
+
57
+ asserts("result of evaluating when number outside of range") do
58
+ Riot::Assertion.new("blue", true) { 31415 }.equals(30000..32000).run(Riot::Situation.new)
59
+ end.equals([:pass, "is equal to 30000..32000 when it is 31415"])
60
+
61
+ context "with block as the expectation" do
62
+ asserts(":pass when block expectation values do not equal") do
63
+ topic.equals { "bazzle" }.run(Riot::Situation.new)
64
+ end.equals([:pass, %Q{is equal to "bazzle" when it is "foo"}])
65
+
66
+ asserts(":fail with message when block expectation values do equal") do
67
+ topic.equals { "foo" }.run(Riot::Situation.new)[0..1]
68
+ end.equals([:fail, %Q{did not expect "foo"}])
69
+ end # with block as the expectation
70
+
71
+ end # A negative assertion macro
@@ -4,33 +4,52 @@ require 'teststrap'
4
4
  # and assertion_test_fails for testing other macros.
5
5
 
6
6
  context "An equivalent_to assertion macro" do
7
- setup do
8
- Riot::Assertion.new("red") { "what" }
9
- end
7
+ setup { Riot::Assertion.new("red") { "what" } }
10
8
 
11
9
  asserts("String is equivalent to 'what'") do
12
- topic.equivalent_to(String).run(Riot::Situation.new) == [:pass, %Q{is equivalent to String}]
13
- end
10
+ topic.equivalent_to(String).run(Riot::Situation.new)
11
+ end.equals([:pass, "is equivalent to String"])
14
12
 
15
13
  asserts("an array is not equivalent to 'what'") do
16
- topic.equivalent_to([]).run(Riot::Situation.new)[0..1] == [:fail, %Q{expected "what" to be equivalent to []}]
17
- end
14
+ topic.equivalent_to([]).run(Riot::Situation.new)[0..1]
15
+ end.equals([:fail, 'expected "what" to be equivalent to []'])
18
16
 
19
17
  context "with numeric topic" do
20
- setup do
21
- Riot::Assertion.new("blue") { 31413 }
22
- end
18
+ setup { Riot::Assertion.new("blue") { 31413 } }
23
19
 
24
20
  asserts(":pass when in expected range") do
25
- topic.equivalent_to(30000..32000).run(Riot::Situation.new) == [:pass, "is equivalent to 30000..32000"]
26
- end
21
+ topic.equivalent_to(30000..32000).run(Riot::Situation.new)
22
+ end.equals([:pass, "is equivalent to 30000..32000"])
27
23
 
28
- context "when not in expected range" do
29
- setup { topic.equivalent_to(32000..33000).run(Riot::Situation.new) }
24
+ asserts ":fail when not in expected range" do
25
+ topic.equivalent_to(32000..33000).run(Riot::Situation.new)[0..1]
26
+ end.equals([:fail, 'expected 31413 to be equivalent to 32000..33000'])
30
27
 
31
- asserts(":fail") { topic.first == :fail }
32
- asserts("message") { topic[1] == %Q{expected 31413 to be equivalent to 32000..33000} }
33
- end
34
28
  end # with numeric topic
35
29
 
36
30
  end # An equivalent_to assertion macro
31
+
32
+ context "A negative equivalent_to assertion macro" do
33
+ setup { Riot::Assertion.new("red", true) { "what" } }
34
+
35
+ asserts("String is not equivalent to 'what'") do
36
+ topic.equivalent_to(String).run(Riot::Situation.new)[0..1]
37
+ end.equals([:fail, 'expected "what" not to be equivalent to String'])
38
+
39
+ asserts("an array is not equivalent to 'what'") do
40
+ topic.equivalent_to([]).run(Riot::Situation.new)
41
+ end.equals([:pass, "is not equivalent to []"])
42
+
43
+ context "with numeric topic" do
44
+ setup { Riot::Assertion.new("blue", true) { 31413 } }
45
+
46
+ asserts(":fail when not in expected range") do
47
+ topic.equivalent_to(30000..32000).run(Riot::Situation.new)[0..1]
48
+ end.equals([:fail, "expected 31413 not to be equivalent to 30000..32000"])
49
+
50
+ asserts ":pass when in expected range" do
51
+ topic.equivalent_to(32000..33000).run(Riot::Situation.new)
52
+ end.equals([:pass, "is not equivalent to 32000..33000"])
53
+
54
+ end # with numeric topic
55
+ end # A negative equivalent_to assertion macro
@@ -1,17 +1,38 @@
1
1
  require 'teststrap'
2
2
 
3
3
  context "An exists assertion macro" do
4
- setup { Riot::Situation.new }
4
+ helper(:assert_exists) do |o|
5
+ Riot::Assertion.new("test") { o }.exists.run(Riot::Situation.new)
6
+ end
5
7
 
6
8
  asserts(":pass when result has a value") do
7
- Riot::Assertion.new("foo") { "foo" }.exists.run(topic)
9
+ assert_exists("foo")
8
10
  end.equals([:pass, "is not nil"])
9
11
 
10
12
  asserts(":pass because empty string is considered a value") do
11
- Riot::Assertion.new("foo") { "" }.exists.run(topic)
13
+ assert_exists("")
12
14
  end.equals([:pass, "is not nil"])
13
15
 
14
16
  asserts(":fail with message when value is nil") do
15
- Riot::Assertion.new("foo") { nil }.exists.run(topic)[0..1]
17
+ assert_exists(nil)[0..1]
16
18
  end.equals([:fail, "expected a non-nil value"])
17
19
  end # An exists assertion macro
20
+
21
+ context "A negative exists assertion macro" do
22
+ helper(:assert_exists) do |o|
23
+ Riot::Assertion.new("test", true) { o }.exists.run(Riot::Situation.new)
24
+ end
25
+
26
+ asserts(":fail when string") do
27
+ assert_exists("foo")[0..1]
28
+ end.equals([:fail, "expected a nil value"])
29
+
30
+ asserts ":fail when string empty" do
31
+ assert_exists("")[0..1]
32
+ end.equals([:fail, "expected a nil value"])
33
+
34
+ asserts(":pass when nil") do
35
+ assert_exists(nil)
36
+ end.equals([:pass, "is nil"])
37
+
38
+ end # A negative exists assertion macro
@@ -11,3 +11,15 @@ context "An includes assertion macro" do
11
11
  topic.includes(99)
12
12
  end
13
13
  end # An includes assertion macro
14
+
15
+ context "A negative includes assertion macro" do
16
+ setup do
17
+ Riot::Assertion.new("an array", true) { [1, 6, 42, 7] }
18
+ end
19
+
20
+ assertion_test_passes("when array doesn't include 69", "does not include 69") { topic.includes(69) }
21
+
22
+ assertion_test_fails("when 42 is included in array", "expected [1, 6, 42, 7] to not include 42") do
23
+ topic.includes(42)
24
+ end
25
+ end
@@ -13,3 +13,18 @@ context "A kind_of assertion macro" do
13
13
  Riot::Assertion.new("foo") { }.kind_of(String)
14
14
  end
15
15
  end # A kind_of assertion macro
16
+
17
+ context "A negative kind_of assertion macro" do
18
+ assertion_test_passes(":pass when specific result is not a kind of String", "is not a kind of String") do
19
+ Riot::Assertion.new("foo", true) { 1 }.kind_of(String)
20
+ end
21
+
22
+ assertion_test_fails(":fail when a kind of String", "expected not kind of String, not String") do
23
+ Riot::Assertion.new("foo", true) { "a" }.kind_of(String)
24
+ end
25
+
26
+ assertion_test_passes(":pass when nil", "is not a kind of String") do
27
+ Riot::Assertion.new("foo", true) { }.kind_of(String)
28
+ end
29
+
30
+ end # A negative kind_of assert macro
@@ -0,0 +1,49 @@
1
+ require 'teststrap'
2
+
3
+ context "A matching assertion macro" do
4
+ setup { Riot::Assertion.new("foo") { "abc" } }
5
+
6
+ assertion_test_passes("when expression matches actual", %Q{matches /abc/}) { topic.matches(/abc/) }
7
+
8
+ assertion_test_fails("when expression fails to match", "expected /abcd/ to match \"abc\"") do
9
+ topic.matches(/abcd/)
10
+ end
11
+
12
+ context "with integer based topic" do
13
+ setup { Riot::Assertion.new("foo") { 42 } }
14
+
15
+ assertion_test_passes("actual value converted to string", %Q{matches /^42$/}) do
16
+ topic.matches(/^42$/)
17
+ end
18
+
19
+ assertion_test_fails("actual value converted to string", %Q{expected /^52$/ to match 42}) do
20
+ topic.matches(/^52$/)
21
+ end
22
+ end
23
+
24
+ end # A matching assertion macro
25
+
26
+ context "A negative matching assertion macro" do
27
+ setup { Riot::Assertion.new("foo", true) { "abc" } }
28
+
29
+ assertion_test_fails("when expression matches actual", 'expected /abc/ not to match "abc"') do
30
+ topic.matches(/abc/)
31
+ end
32
+
33
+ assertion_test_passes("when expression does not match", 'does not match /abcd/') do
34
+ topic.matches(/abcd/)
35
+ end
36
+
37
+ context "with integer based topic" do
38
+ setup { Riot::Assertion.new("foo", true) { 42 } }
39
+
40
+ assertion_test_fails("actual value converted to string", 'expected /^42$/ not to match 42') do
41
+ topic.matches(/^42$/)
42
+ end
43
+
44
+ assertion_test_passes("actual value converted to string", 'does not match /^52$/') do
45
+ topic.matches(/^52$/)
46
+ end
47
+ end
48
+
49
+ end # A negative matching assertion macro