public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
shoulda / test / other / convert_to_should_syntax_test.rb
100644 64 lines (45 sloc) 1.307 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
require 'test/unit'
 
class ConvertToShouldSyntaxTest < Test::Unit::TestCase # :nodoc:
 
  BEFORE_FIXTURE = <<-EOS
class DummyTest < Test::Unit::TestCase
 
should "Not change this_word_with_underscores" do
end
 
def test_should_be_working
assert true
end
 
def test_some_cool_stuff
assert true
end
 
def non_test_method
end
 
end
EOS
 
  AFTER_FIXTURE = <<-EOS
class DummyTest < Test::Unit::TestCase
 
should "Not change this_word_with_underscores" do
end
 
should "be working" do
assert true
end
 
should "RENAME ME: test some cool stuff" do
assert true
end
 
def non_test_method
end
 
end
EOS
  
  FIXTURE_PATH = "./convert_to_should_syntax_fixture.dat"
 
  RUBY = ENV['RUBY'] || 'ruby'
 
  def test_convert_to_should_syntax
    File.open(FIXTURE_PATH, "w") {|f| f.write(BEFORE_FIXTURE)}
    cmd = "#{RUBY} #{File.join(File.dirname(__FILE__), '../../bin/convert_to_should_syntax')} #{FIXTURE_PATH}"
    output = `#{cmd}`
    File.unlink($1) if output.match(/has been stored in '([^']+)/)
    assert_match(/has been converted/, output)
    result = IO.read(FIXTURE_PATH)
    assert_equal result, AFTER_FIXTURE
  end
 
  def teardown
    File.unlink(FIXTURE_PATH)
  end
 
end