1 require File.dirname(__FILE__) + '/../spec_helper.rb'
2 require 'spec/translator'
4 describe "Translator" do
6 @t = Spec::Translator.new
9 it "should translate files" do
10 from = File.dirname(__FILE__) + '/..'
11 to = "#{Dir.tmpdir}/translated_specs"
12 @t.translate_dir(from, to)
15 it "should translate context_setup do" do
23 it "should translate context_setup {foo}" do
25 "context_setup {foo}\n"
27 "before(:all) {foo}\n"
31 it "should translate context ' to describe '" do
33 "context 'Translator' do\n"
35 "describe 'Translator' do\n"
39 it 'should translate context " to describe "' do
41 'context "Translator"'
43 'describe "Translator"'
47 it 'should translate spaces then context " to describe "' do
49 ' context "Translator"'
51 ' describe "Translator"'
55 it "should not translate context=foo" do
56 @t.translate_line(' context=foo').should eql(' context=foo')
59 it "should not translate context = foo" do
60 @t.translate_line(' context = foo').should eql(' context = foo')
63 it "should not translate context = foo" do
64 @t.translate_line(' context = foo').should eql(' context = foo')
67 it "should translate should_be_close" do
68 @t.translate_line('5.0.should_be_close(5.0, 0.5)').should eql('5.0.should be_close(5.0, 0.5)')
71 it "should translate should_not_raise" do
72 @t.translate_line('lambda { self.call }.should_not_raise').should eql('lambda { self.call }.should_not raise_error')
75 it "should translate should_throw" do
76 @t.translate_line('lambda { self.call }.should_throw').should eql('lambda { self.call }.should throw_symbol')
79 it "should not translate 0.9 should_not" do
80 @t.translate_line('@target.should_not @matcher').should eql('@target.should_not @matcher')
83 it "should leave should_not_receive" do
84 @t.translate_line('@mock.should_not_receive(:not_expected).with("unexpected text")').should eql('@mock.should_not_receive(:not_expected).with("unexpected text")')
87 it "should leave should_receive" do
88 @t.translate_line('@mock.should_receive(:not_expected).with("unexpected text")').should eql('@mock.should_receive(:not_expected).with("unexpected text")')
91 it "should translate multi word predicates" do
92 @t.translate_line('foo.should_multi_word_predicate').should eql('foo.should be_multi_word_predicate')
95 it "should translate multi word predicates prefixed with be" do
96 @t.translate_line('foo.should_be_multi_word_predicate').should eql('foo.should be_multi_word_predicate')
99 it "should translate be(expected) to equal(expected)" do
100 @t.translate_line('foo.should_be :cool').should eql('foo.should equal :cool')
103 it "should translate instance_of" do
104 @t.translate_line('5.should_be_an_instance_of(Integer)').should eql('5.should be_an_instance_of(Integer)')
107 it "should translate should_be <" do
108 @t.translate_line('3.should_be < 4').should eql('3.should be < 4')
111 it "should translate should_be <=" do
112 @t.translate_line('3.should_be <= 4').should eql('3.should be <= 4')
115 it "should translate should_be >=" do
116 @t.translate_line('4.should_be >= 3').should eql('4.should be >= 3')
119 it "should translate should_be >" do
120 @t.translate_line('4.should_be > 3').should eql('4.should be > 3')
123 it "should translate should_be_happy" do
124 @t.translate_line("4.should_be_happy").should eql("4.should be_happy")
127 it "should translate custom method taking regexp with parenthesis" do
128 @t.translate_line("@browser.should_contain_text(/Sn.rrunger og annet rusk/)").should eql("@browser.should be_contain_text(/Sn.rrunger og annet rusk/)")
131 it "should translate custom method taking regexp without parenthesis" do
132 @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")
135 it "should translate should_not_be_nil" do
136 @t.translate_line("foo.should_not_be_nil\n").should eql("foo.should_not be_nil\n")
139 it "should translate kind of" do
140 @t.translate_line('@object.should_be_kind_of(MessageExpectation)').should(
141 eql('@object.should be_kind_of(MessageExpectation)'))
144 it "should translate should_be_true" do
145 @t.translate_line("foo.should_be_true\n").should eql("foo.should be_true\n")
148 # [#9674] spec_translate incorrectly handling shoud_match, when regexp in a var, in a block
149 # http://rubyforge.org/tracker/?func=detail&atid=3149&aid=9674&group_id=797
150 it "should translate should_match on a regexp, in a var, in a block" do
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")
152 @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")
155 # From Rubinius specs
156 it "should translate close_to without parens" do
157 @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")
160 # [#9882] 0.9 Beta 1 - translator bugs
161 # http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
162 it "should support symbol arguments" do
164 "lambda { sequence.parse('bar') }.should_throw :ZeroWidthParseSuccess\n"
166 "lambda { sequence.parse('bar') }.should throw_symbol(:ZeroWidthParseSuccess)\n"
170 # [#9882] 0.9 Beta 1 - translator bugs
171 # http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
172 it "should support instance var arguments" do
174 "a.should_eql @local"
176 "a.should eql(@local)"
180 # [#9882] 0.9 Beta 1 - translator bugs
181 # http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
182 it "should support lambdas as expecteds" do
184 "@parslet.should_not_eql lambda { nil }.to_parseable"
186 "@parslet.should_not eql(lambda { nil }.to_parseable)"
190 # [#9882] 0.9 Beta 1 - translator bugs
191 # http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
192 it "should support fully qualified names" do
194 "results.should_be_kind_of SimpleASTLanguage::Identifier"
196 "results.should be_kind_of(SimpleASTLanguage::Identifier)"
200 # [#9882] 0.9 Beta 1 - translator bugs
201 # http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
202 # it "should leave whitespace between expression and comments" do
204 # "lambda { @instance.foo = foo }.should_raise NoMethodError # no writer defined"
206 # "lambda { @instance.foo = foo }.should raise_error(NoMethodError) # no writer defined"
210 it "should translate redirects" do
212 "controller.should_redirect_to 'http://not_existing_domain_for_novalis.test.host/404.html'"
214 "controller.should redirect_to('http://not_existing_domain_for_novalis.test.host/404.html')"
218 it "should translate :any_args" do
220 "mock.should_receive(:foo).with(:any_args)"
222 "mock.should_receive(:foo).with(any_args)"
226 it "should translate :anything" do
228 "mock.should_receive(:foo).with(:anything)"
230 "mock.should_receive(:foo).with(anything)"
234 it "should translate :boolean" do
236 "mock.should_receive(:foo).with(:boolean)"
238 "mock.should_receive(:foo).with(boolean)"
242 it "should translate :no_args" do
244 "mock.should_receive(:foo).with(:no_args)"
246 "mock.should_receive(:foo).with(no_args)"
250 it "should translate :numeric" do
252 "mock.should_receive(:foo).with(:numeric)"
254 "mock.should_receive(:foo).with(an_instance_of(Numeric))"
258 it "should translate :string" do
260 "mock.should_receive(:foo).with(:string)"
262 "mock.should_receive(:foo).with(an_instance_of(String))"