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
96
97
98
99
100
101
102
103
104
|
# File 'lib/rspec_extensions.rb', line 50
def translate_line(line)
line.gsub!(/:any_args/, 'any_args')
line.gsub!(/:anything/, 'anything')
line.gsub!(/:boolean/, 'boolean')
line.gsub!(/:no_args/, 'no_args')
line.gsub!(/:numeric/, 'an_instance_of(Numeric)')
line.gsub!(/:string/, 'an_instance_of(String)')
return line if line =~ /(should_not|should)_receive/
line.gsub!(/(^\s*)context([\s*|\(]['|"|A-Z])/, '\1describe\2')
line.gsub!(/(^\s*)spec([\s*|\(]['|"|A-Z])/, '\1describe\2') line.gsub!(/(^\s*)specification([\s*|\(]['|"|A-Z])/, '\1describe\2') line.gsub!(/(^\s*)specify([\s*|\(]['|"|A-Z])/, '\1it\2')
line.gsub!(/(^\s*)scenario([\s*|\(]['|"|A-Z])/, '\1it\2') line.gsub!(/(^\s*)story([\s*|\(]['|"|A-Z])/, '\1it\2') line.gsub!(/(^\s*)context_setup(\s*[do|\{])/, '\1before(:all)\2')
line.gsub!(/(^\s*)context_teardown(\s*[do|\{])/, '\1after(:all)\2')
line.gsub!(/(^\s*)setup(\s*[do|\{])/, '\1before(:each)\2')
line.gsub!(/(^\s*)teardown(\s*[do|\{])/, '\1after(:each)\2')
if line =~ /(.*\.)(should_not|should)(?:_be)(?!_)(.*)/m
pre = $1
should = $2
post = $3
be_or_equal = post =~ /(<|>)/ ? "be" : "equal"
return "#{pre}#{should} #{be_or_equal}#{post}"
end
if line =~ /(.*\.)(should_not|should)_(?!not)\s*(.*)/m
pre = $1
should = $2
post = $3
post.gsub!(/^raise/, 'raise_error')
post.gsub!(/^throw/, 'throw_symbol')
unless standard_matcher?(post)
post = "be_#{post}"
end
post.gsub!(/^(\w+)\s+([\w|\.|\,|\(.*\)|\'|\"|\:|@| ]+)(\})/, '\1(\2)\3') post.gsub!(/^(redirect_to)\s+(.*)/, '\1(\2)') post.gsub!(/^(\w+)\s+([\w|\.|\,|\(.*\)|\{.*\}|\'|\"|\:|@| ]+)/, '\1(\2)')
post.gsub!(/(\s+\))/, ')')
post.gsub!(/\)\}/, ') }')
post.gsub!(/^(\w+)\s+(\/.*\/)/, '\1(\2)') line = "#{pre}#{should} #{post}"
end
line
end
|