Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 133 lines (103 sloc) 2.675 kb
aaf01e7 @alexch minor update to examples.rb
alexch authored
1 # run this file to see some sample Wrong failures
2
96a8228 @alexch examples
alexch authored
3 puts "RUBY_VERSION=#{RUBY_VERSION}"
4 puts
5
6 require "rubygems"
7 require "bundler"
8 Bundler.setup
9
10 require "./lib/wrong"
e511c4e @alexch "include Wrong" works since Wrong module now includes assert and helper ...
alexch authored
11 include Wrong
96a8228 @alexch examples
alexch authored
12
dbaf06a @alexch reads settings from a .wrong file
alexch authored
13 Wrong.config.color # or just put the line "color" in a file called ".wrong" in the current dir
96a8228 @alexch examples
alexch authored
14
44fb83a @alexch verbose mode
alexch authored
15 Wrong.config.verbose # you probably don't want to do this in your own code
16 assert("basic math") { 2 + 2 == 4 }
17
838bbbe @alexch wrap and indent long values
alexch authored
18 def example(name = nil)
19 puts "\n=== Example#{":" if name} #{name}"
96a8228 @alexch examples
alexch authored
20 e = rescuing do
21 yield
22 end
23 puts e
24 puts
25 end
26
b14620e @alexch improve docs
alexch authored
27 # ignore all the "example" statements in this file; they're so the failed assertions don't exit the process
c5e9000 @alexch improve docs
alexch authored
28
b14620e @alexch improve docs
alexch authored
29 example do
aaf01e7 @alexch minor update to examples.rb
alexch authored
30 assert {2==1}
31 end
96a8228 @alexch examples
alexch authored
32
b14620e @alexch improve docs
alexch authored
33 example do
aaf01e7 @alexch minor update to examples.rb
alexch authored
34 x = 7; y = 10; assert { x == 7 && y == 11 }
35 end
96a8228 @alexch examples
alexch authored
36
b14620e @alexch improve docs
alexch authored
37 example do
c5e9000 @alexch improve docs
alexch authored
38 age = 24
39 name = "Gaga"
40 assert { age >= 18 && ["Britney", "Snooki"].include?(name) }
41 end
42
b14620e @alexch improve docs
alexch authored
43 example do
aaf01e7 @alexch minor update to examples.rb
alexch authored
44 assert { 'hand'.include?('bird') }
45 end
96a8228 @alexch examples
alexch authored
46
b14620e @alexch improve docs
alexch authored
47 example do
aaf01e7 @alexch minor update to examples.rb
alexch authored
48 deny { 'abc'.include?('bc') }
49 end
57cfb53 @alexch examples for string and array diff
alexch authored
50
b14620e @alexch improve docs
alexch authored
51 example do
804e7be @alexch Ruby 1.9.1 and JRuby fixes for 0.4.5
alexch authored
52 assert { "the quick brown fox jumped over the lazy dog" == "the quick brown hamster jumped over the lazy gerbil" }
57cfb53 @alexch examples for string and array diff
alexch authored
53 end
54
b14620e @alexch improve docs
alexch authored
55 example do
4493d7d @alexch update readme and examples
alexch authored
56 fun_planets = ["venus", "mars", "pluto", "saturn"]
57 smart_planets = ["venus", "earth", "pluto", "neptune"]
58 assert { fun_planets == smart_planets }
57cfb53 @alexch examples for string and array diff
alexch authored
59 end
60
ae25366 @alexch docs & refactoring
alexch authored
61 ex = rescuing{raise "vanilla"}
b14620e @alexch improve docs
alexch authored
62 example { assert{ ex.message == "chocolate" } }
ae25366 @alexch docs & refactoring
alexch authored
63
b14620e @alexch improve docs
alexch authored
64 example do
ae25366 @alexch docs & refactoring
alexch authored
65 assert { rescuing { raise "vanilla" }.message == "chocolate" }
66 end
67
b14620e @alexch improve docs
alexch authored
68 example do
96a8228 @alexch examples
alexch authored
69 assert{ rescuing{raise "vanilla"}.message == "chocolate" }
70 end
71
72 @foo = "bar"
73 class Foo
74 def initialize(*args)
75 end
76 end
77
b14620e @alexch improve docs
alexch authored
78 example do
aaf01e7 @alexch minor update to examples.rb
alexch authored
79 assert { Foo.new(1, Foo.new(3,4) ,3) == 4 }
80 end
96a8228 @alexch examples
alexch authored
81
2e94ce4 @alexch capturing helper, rspec adapter
alexch authored
82 assert { capturing { puts "hi" } == "hi\n" }
83 assert { capturing(:stderr) { $stderr.puts "hi" } == "hi\n" }
84
85 out, err = capturing(:stdout, :stderr) do
86 print "hi"
87 $stderr.print "bye"
88 end
89 assert { out == "hi" and err == "bye"}
20a8af8 @alexch released 0.3.0
alexch authored
90
b14620e @alexch improve docs
alexch authored
91 example do
20a8af8 @alexch released 0.3.0
alexch authored
92 time = 6
93 money = 27
94 assert { time == money }
95 end
f67567f @alexch behold the awesome power of d!
alexch authored
96
b14620e @alexch improve docs
alexch authored
97 example do
a1b4792 @alexch iimprove rspec integration testing
alexch authored
98 assert { "123".reverse == "323" }
99 end
100
b14620e @alexch improve docs
alexch authored
101 example do
ae25366 @alexch docs & refactoring
alexch authored
102 hash = {:flavor => "vanilla"}
c49209d @alexch use pp instead of inspect for values
alexch authored
103 exception_with_newlines = Exception.new(hash.to_yaml.chomp)
ae25366 @alexch docs & refactoring
alexch authored
104 assert("showing indentation of details") { rescuing { raise exception_with_newlines }.message.include?(":flavor: chocolate") }
105 end
106
838bbbe @alexch wrap and indent long values
alexch authored
107 example "indentation of long values" do
108 alphabet = "abcdefghijklmnopqrstuvwxyz"
109 assert { (alphabet * 10).include? "123" }
110 end
ae25366 @alexch docs & refactoring
alexch authored
111
838bbbe @alexch wrap and indent long values
alexch authored
112 example "indentation of long values" do
113 hash = {}
114 100.times do
115 hash[(rand * 1000).to_i] = (rand * 1000).to_i
116 end
117 assert { hash["abc"] }
118 end
119
120 example "the d method" do
121 x = 7
122 d { x * 2 }
123 end
cae852f @alexch eventually: docs, included in Wrong module
alexch authored
124
125 example "eventually fails after 5 seconds" do
126 eventually { false }
127 end
128
129 example "eventually fails with a friendly error" do
130 x = 2
131 eventually { x + x == 5 }
132 end
Something went wrong with that request. Please try again.