Skip to content

Commit

Permalink
examples converted to the new api, tested with examples.rb which stil…
Browse files Browse the repository at this point in the history
…l uses the old api

No more:
  Check(foo).is("bar")

Instead do:
  Assert(foo == "bar")
  • Loading branch information
Myles Byrne committed Apr 13, 2010
1 parent ab22115 commit f7b223c
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 105 deletions.
10 changes: 8 additions & 2 deletions Rakefile
Expand Up @@ -16,8 +16,14 @@ rescue LoadError
puts "Install jeweler to build gem"
end

task :examples do
ruby "-rubygems", "examples.rb"
desc "runs the examples with the rubygems version of exemplor (you must gem install the gem for this to work)"
task :examples, [:filter] do |_,args|
ruby "-rubygems", "examples.rb", (args.filter || '')
end

desc "runs the examples with the development version (i.e. the one in this dir) of exemplor"
task :dev, [:filter] do |_,args|
ruby '-rubygems', '-I', 'lib', 'examples.rb', (args.filter || '')
end

task :test => :examples
19 changes: 13 additions & 6 deletions examples.rb
@@ -1,6 +1,8 @@
# uses the gem version, not the one being tested
require 'exemplor'

# Each test runs in a subshell, exemplor is tested with exemplor but from
# a version running in a different process. Exemplor hates unit tests.

eg "Exemplor.version comes from the version file" do
version = `ruby -rubygems -Ilib -e "require 'exemplor' ; print Exemplor.version"`
Check(version).is(File.read(__FILE__.sub('examples.rb','VERSION')))
Expand All @@ -24,25 +26,30 @@ def examples filenames
end
end

# slow because each test runs in a subshell
examples %w[
no_checks
oneliner
no_checks_non_string
with_checks
check_with_disambiguation

simple_show
multi_show
show_with_disambiguation

assertion_success
assertion_failure
assertion_success_and_failure
assertion_success_and_info
failure_halts_execution

helpers
with_setup
checking_nil
dumping_classes
showing_classes
check_parsing
]

# I never use this guy, candidate for removal
examples %w[oneliner]

eg.helpers do
# Exemplor outputs valid yaml, for some of our assertions it's easier to use
# the parsed structure
Expand Down
8 changes: 3 additions & 5 deletions examples/assertion_failure.rb
Expand Up @@ -2,15 +2,13 @@

eg 'Assertion failure' do
list = [1, 2, 3]
Check(list.first).is(2)
Assert(list.first == 2)
end

__END__

- name: Assertion failure
status: failure
result:
- name: list.first
status: failure
expected: 2
actual: 1
- name: list.first == 2
status: failure
5 changes: 2 additions & 3 deletions examples/assertion_success.rb
Expand Up @@ -2,7 +2,7 @@

eg 'Asserting first is first' do
list = [1, 2, 3]
Check(list.first).is(1)
Assert(list.first)
end

__END__
Expand All @@ -11,5 +11,4 @@
status: success
result:
- name: list.first
status: success
result: 1
status: success
20 changes: 8 additions & 12 deletions examples/assertion_success_and_failure.rb
Expand Up @@ -2,24 +2,20 @@

eg 'Some successes, then a fail' do
list = [1, 2, 3]
Check(list.first).is(1)
Check(list[1]).is(2)
Check(list.last).is(1) # fail!
Check(list[2]).is(3) # would be successful but we never get here
Assert(list.first == 1)
Assert(list[1] == 2)
Assert(list.last == 1) # fail!
Assert(list[2] == 3) # would be successful but we never get here
end

__END__

- name: Some successes, then a fail
status: failure
result:
- name: list.first
- name: list.first == 1
status: success
result: 1
- name: list[1]
- name: list[1] == 2
status: success
result: 2
- name: list.last
status: failure
expected: 1
actual: 3
- name: list.last == 1
status: failure
19 changes: 8 additions & 11 deletions examples/assertion_success_and_info.rb
Expand Up @@ -2,26 +2,23 @@

eg 'Some successes, then an info' do
list = [1, 2, 3]
Check(list.first).is(1)
Check(list[1]).is(2)
Check(list.last) # the info one
Check(list[2]).is(3)
Assert(list.first ==1)
Assert(list[1] == 2)
Show(list.last) # the info one
Assert(list[2] == 3)
end

__END__

- name: Some successes, then an info
status: info (with checks)
result:
- name: list.first
- name: list.first ==1
status: success
result: 1
- name: list[1]
- name: list[1] == 2
status: success
result: 2
- name: list.last
status: info
result: 3
- name: list[2]
status: success
result: 3
- name: list[2] == 3
status: success
25 changes: 8 additions & 17 deletions examples/check_parsing.rb
Expand Up @@ -5,29 +5,26 @@ def foo() 'bar' end
end

eg "plain call" do
Check(foo)
Show(foo)
end

eg "whitespace after the call (seriously)" do
Check(foo)
Show(foo)
end

eg "comment after the call" do
Check(foo) # comment!
Show(foo) # comment!
end

eg "with brackets" do
Check(String.new('test'))
end

eg "with brackets and is" do
Check(String.new('test')).is("test")
Show(String.new('test'))
end

eg "with disambiguation" do
Check(foo)['bar'].is('bar')
Show(foo)['bar']
end


__END__

- name: plain call
Expand All @@ -54,15 +51,9 @@ def foo() 'bar' end
- name: String.new('test')
status: info
result: test
- name: with brackets and is
status: success
result:
- name: String.new('test')
status: success
result: test
- name: with disambiguation
status: success
status: info (with checks)
result:
- name: foo bar
status: success
status: info
result: bar
11 changes: 6 additions & 5 deletions examples/checking_nil.rb
@@ -1,11 +1,13 @@
require 'exemplor'

# this is kind of a compromise, looking for better ideas

eg "checking nil works correctly" do
Check(nil)
Show(nil)
end

eg "asserting for nil works correctly" do
Check(nil).is(nil)
Assert(nil == nil)
end

__END__
Expand All @@ -19,6 +21,5 @@
- name: asserting for nil works correctly
status: success
result:
- name: nil
status: success
result:
- name: nil == nil
status: success
8 changes: 3 additions & 5 deletions examples/failure_halts_execution.rb
Expand Up @@ -2,7 +2,7 @@

eg 'Failures halt execution' do
list = [1, 2, 3]
Check(list.first).is(1_000_000) # fail!
Assert(list.first == 1_000_000) # fail!
raise "foo" # we never get here
end

Expand All @@ -11,7 +11,5 @@
- name: Failures halt execution
status: failure
result:
- name: list.first
status: failure
expected: 1000000
actual: 1
- name: list.first == 1_000_000
status: failure
6 changes: 3 additions & 3 deletions examples/with_checks.rb → examples/multi_show.rb
Expand Up @@ -2,9 +2,9 @@

eg 'Accessing different parts of an array' do
list = [1, 2, 3]
Check(list.first)
Check(list[1])
Check(list.last)
Show(list.first)
Show(list[1])
Show(list.last)
end

__END__
Expand Down
Expand Up @@ -2,9 +2,9 @@

eg 'Array appending' do
list = [1, 42]
Check(list.last)["before append"]
Show(list.last)["before append"]
list << 2
Check(list.last)["after append"]
Show(list.last)["after append"]
end

__END__
Expand Down
Expand Up @@ -5,7 +5,7 @@
end

eg "class name is printed when check is given a class" do
Check(Object)
Show(Object)
end

__END__
Expand Down
15 changes: 15 additions & 0 deletions examples/simple_show.rb
@@ -0,0 +1,15 @@
require 'exemplor'

eg 'Showing the value of some expression' do
list = [1, 2, 3]
Show(list.first)
end

__END__

- name: Showing the value of some expression
status: info (with checks)
result:
- name: list.first
status: info
result: 1
20 changes: 10 additions & 10 deletions examples/ten_percent_failures.rb
@@ -1,12 +1,12 @@
require 'exemplor'

eg { Check(1).is(1) }
eg { Check(2).is(2) }
eg { Check(3).is(3) }
eg { Check(4).is(4) }
eg { Check(5).is(5) }
eg { Check(6).is(6) }
eg { Check(7).is(7) }
eg { Check(8).is(8) }
eg { Check(9).is(9) }
eg { Check(false).is(true) }
eg { Assert(1 == 1) }
eg { Assert(2 == 2) }
eg { Assert(3 == 3) }
eg { Assert(4 == 4) }
eg { Assert(5 == 5) }
eg { Assert(6 == 6) }
eg { Assert(7 == 7) }
eg { Assert(8 == 8) }
eg { Assert(9 == 9) }
eg { Assert(false == true) }
12 changes: 5 additions & 7 deletions examples/with_setup.rb
Expand Up @@ -4,24 +4,22 @@

eg 'Modified env' do
@str << " bar"
Check(@str).is("foo bar")
Assert(@str == 'foo bar')
end

eg 'Unmodified env' do
Check(@str).is("foo")
Assert(@str == 'foo')
end

__END__

- name: Modified env
status: success
result:
- name: "@str"
- name: "@str == 'foo bar'"
status: success
result: foo bar
- name: Unmodified env
status: success
result:
- name: "@str"
status: success
result: foo
- name: "@str == 'foo'"
status: success

0 comments on commit f7b223c

Please sign in to comment.