1 require File.dirname(__FILE__) + '/../spec_helper.rb'
3 describe "Translator" do
5 @t = Spec::Translator.new
8 it "should translate files" do
9 from = File.dirname(__FILE__) + '/..'
10 to = "#{Dir.tmpdir}/translated_specs"
11 @t.translate_dir(from, to)
14 it "should translate context_setup do" do
22 it "should translate context_setup {foo}" do
24 "context_setup {foo}\n"
26 "before(:all) {foo}\n"
30 it "should translate context ' to describe '" do
32 "context 'Translator' do\n"
34 "describe 'Translator' do\n"
38 it 'should translate context " to describe "' do
40 'context "Translator"'
42 'describe "Translator"'
46 it 'should translate spaces then context " to describe "' do
48 ' context "Translator"'
50 ' describe "Translator"'
54 it "should not translate context=foo" do
55 @t.translate_line(' context=foo').should eql(' context=foo')
58 it "should not translate context = foo" do
59 @t.translate_line(' context = foo').should eql(' context = foo')
62 it "should not translate context = foo" do
63 @t.translate_line(' context = foo').should eql(' context = foo')
66 it "should translate should_be_close" do
67 @t.translate_line('5.0.should_be_close(5.0, 0.5)').should eql('5.0.should be_close(5.0, 0.5)')
70 it "should translate should_not_raise" do
71 @t.translate_line('lambda { self.call }.should_not_raise').should eql('lambda { self.call }.should_not raise_error')
74 it "should translate should_throw" do
75 @t.translate_line('lambda { self.call }.should_throw').should eql('lambda { self.call }.should throw_symbol')
78 it "should not translate 0.9 should_not" do
79 @t.translate_line('@target.should_not @matcher').should eql('@target.should_not @matcher')
82 it "should leave should_not_receive" do
83 @t.translate_line('@mock.should_not_receive(:not_expected).with("unexpected text")').should eql('@mock.should_not_receive(:not_expected).with("unexpected text")')
86 it "should leave should_receive" do
87 @t.translate_line('@mock.should_receive(:not_expected).with("unexpected text")').should eql('@mock.should_receive(:not_expected).with("unexpected text")')
90 it "should translate multi word predicates" do
91 @t.translate_line('foo.should_multi_word_predicate').should eql('foo.should be_multi_word_predicate')
94 it "should translate multi word predicates prefixed with be" do
95 @t.translate_line('foo.should_be_multi_word_predicate').should eql('foo.should be_multi_word_predicate')
98 it "should translate be(expected) to equal(expected)" do
99 @t.translate_line('foo.should_be :cool').should eql('foo.should equal :cool')
102 it "should translate instance_of" do
103 @t.translate_line('5.should_be_an_instance_of(Integer)').should eql('5.should be_an_instance_of(Integer)')
106 it "should translate should_be <" do
107 @t.translate_line('3.should_be < 4').should eql('3.should be < 4')
110 it "should translate should_be <=" do
111 @t.translate_line('3.should_be <= 4').should eql('3.should be <= 4')
114 it "should translate should_be >=" do
115 @t.translate_line('4.should_be >= 3').should eql('4.should be >= 3')
118 it "should translate should_be >" do
119 @t.translate_line('4.should_be > 3').should eql('4.should be > 3')
122 it "should translate should_be_happy" do
123 @t.translate_line("4.should_be_happy").should eql("4.should be_happy")
126 it "should translate custom method taking regexp with parenthesis" do
127 @t.translate_line("@browser.should_contain_text(/Sn.rrunger og annet rusk/)").should eql("@browser.should be_contain_text(/Sn.rrunger og annet rusk/)")
130 it "should translate custom method taking regexp without parenthesis" do
131 @t.translate_line("@browser.should_contain_text /Sn.rrunger og annet rusk/\n").should eql("@browser.should be_contain_text(/Sn.rrunger og annet rusk/)\n")
134 it "should translate should_not_be_nil" do
135 @t.translate_line("foo.should_not_be_nil\n").should eql("foo.should_not be_nil\n")
138 it "should translate kind of" do
139 @t.translate_line('@object.should_be_kind_of(MessageExpectation)').should(
140 eql('@object.should be_kind_of(MessageExpectation)'))
143 it "should translate should_be_true" do
144 @t.translate_line("foo.should_be_true\n").should eql("foo.should be_true\n")
147 # [#9674] spec_translate incorrectly handling shoud_match, when regexp in a var, in a block
148 # http://rubyforge.org/tracker/?func=detail&atid=3149&aid=9674&group_id=797
149 it "should translate should_match on a regexp, in a var, in a block" do
150 @t.translate_line("collection.each { |c| c.should_match a_regexp_in_a_var }\n").should eql("collection.each { |c| c.should match(a_regexp_in_a_var) }\n")
151 @t.translate_line("collection.each{|c| c.should_match a_regexp_in_a_var}\n").should eql("collection.each{|c| c.should match(a_regexp_in_a_var) }\n")
154 # From Rubinius specs
155 it "should translate close_to without parens" do
156 @t.translate_line("end.should_be_close 3.14159_26535_89793_23846, TOLERANCE\n").should eql("end.should be_close(3.14159_26535_89793_23846, TOLERANCE)\n")
159 # [#9882] 0.9 Beta 1 - translator bugs
160 # http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
161 it "should support symbol arguments" do
163 "lambda { sequence.parse('bar') }.should_throw :ZeroWidthParseSuccess\n"
165 "lambda { sequence.parse('bar') }.should throw_symbol(:ZeroWidthParseSuccess)\n"
169 # [#9882] 0.9 Beta 1 - translator bugs
170 # http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
171 it "should support instance var arguments" do
173 "a.should_eql @local"
175 "a.should eql(@local)"
179 # [#9882] 0.9 Beta 1 - translator bugs
180 # http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
181 it "should support lambdas as expecteds" do
183 "@parslet.should_not_eql lambda { nil }.to_parseable"
185 "@parslet.should_not eql(lambda { nil }.to_parseable)"
189 # [#9882] 0.9 Beta 1 - translator bugs
190 # http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
191 it "should support fully qualified names" do
193 "results.should_be_kind_of SimpleASTLanguage::Identifier"
195 "results.should be_kind_of(SimpleASTLanguage::Identifier)"
199 # [#9882] 0.9 Beta 1 - translator bugs
200 # http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
201 # it "should leave whitespace between expression and comments" do
203 # "lambda { @instance.foo = foo }.should_raise NoMethodError # no writer defined"
205 # "lambda { @instance.foo = foo }.should raise_error(NoMethodError) # no writer defined"
209 it "should translate redirects" do
211 "controller.should_redirect_to 'http://not_existing_domain_for_novalis.test.host/404.html'"
213 "controller.should redirect_to('http://not_existing_domain_for_novalis.test.host/404.html')"
217 it "should translate :any_args" do
219 "mock.should_receive(:foo).with(:any_args)"
221 "mock.should_receive(:foo).with(any_args)"
225 it "should translate :anything" do
227 "mock.should_receive(:foo).with(:anything)"
229 "mock.should_receive(:foo).with(anything)"
233 it "should translate :boolean" do
235 "mock.should_receive(:foo).with(:boolean)"
237 "mock.should_receive(:foo).with(boolean)"
241 it "should translate :no_args" do
243 "mock.should_receive(:foo).with(:no_args)"
245 "mock.should_receive(:foo).with(no_args)"
249 it "should translate :numeric" do
251 "mock.should_receive(:foo).with(:numeric)"
253 "mock.should_receive(:foo).with(an_instance_of(Numeric))"
257 it "should translate :string" do
259 "mock.should_receive(:foo).with(:string)"
261 "mock.should_receive(:foo).with(an_instance_of(String))"