Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 96 lines (73 sloc) 1.691 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
# run this file to see some sample Wrong failures

puts "RUBY_VERSION=#{RUBY_VERSION}"
puts

require "rubygems"
require "bundler"
Bundler.setup

require "./lib/wrong"

include Wrong

Wrong.config[:color] = true

def failing
  e = rescuing do
    yield
  end
  puts e
  puts
end

# ignore all the "failing" statements in this file; they're so the failed assertions don't exit the process

failing do
  assert {2==1}
end

failing do
  x = 7; y = 10; assert { x == 7 && y == 11 }
end

failing do
  age = 24
  name = "Gaga"
  assert { age >= 18 && ["Britney", "Snooki"].include?(name) }
end

failing do
  assert { 'hand'.include?('bird') }
end

failing do
  deny { 'abc'.include?('bc') }
end

#require "wrong/message/string_diff" TODO: make string_diff use "diff-lcs" not "diff" gem
failing do
  assert { "the quick brown fox jumped over the lazy dog" ==
           "the quick brown hamster jumped over the lazy gerbil" }
end

require "wrong/message/array_diff"
failing do
  fun_planets = ["venus", "mars", "pluto", "saturn"]
  smart_planets = ["venus", "earth", "pluto", "neptune"]
  assert { fun_planets == smart_planets }
end

failing do
  assert{ rescuing{raise "vanilla"}.message == "chocolate" }
end

@foo = "bar"
class Foo
  def initialize(*args)
  end
end

failing do
  assert { Foo.new(1, Foo.new(3,4) ,3) == 4 }
end

assert { capturing { puts "hi" } == "hi\n" }
assert { capturing(:stderr) { $stderr.puts "hi" } == "hi\n" }

out, err = capturing(:stdout, :stderr) do
  print "hi"
  $stderr.print "bye"
end
assert { out == "hi" and err == "bye"}

failing do
  time = 6
  money = 27
  assert { time == money }
end

failing do
  assert { "123".reverse == "323" }
end

x = 7
d { x * 2 }
Something went wrong with that request. Please try again.