Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / rspec / spec / spec / translator_spec.rb
blobdbe4ba63c8b5404745fa8744ef3ddf5567ec9402
1 require File.dirname(__FILE__) + '/../spec_helper.rb'
3 describe "Translator" do
4   before do
5     @t = Spec::Translator.new
6   end
7   
8   it "should translate files" do
9     from = File.dirname(__FILE__) + '/..'
10     to = "#{Dir.tmpdir}/translated_specs"
11     @t.translate_dir(from, to)
12   end
14   it "should translate context_setup  do" do
15     @t.translate_line(
16       "context_setup  do\n"
17     ).should eql(
18       "before(:all)  do\n"
19     )
20   end
22   it "should translate context_setup  {foo}" do
23     @t.translate_line(
24       "context_setup  {foo}\n"
25     ).should eql(
26       "before(:all)  {foo}\n"
27     )
28   end
29   
30   it "should translate context ' to describe '" do
31     @t.translate_line(
32       "context 'Translator' do\n"
33     ).should eql(
34       "describe 'Translator' do\n"
35     )
36   end
38   it 'should translate context " to describe "' do
39     @t.translate_line(
40       'context "Translator"'
41     ).should eql(
42       'describe "Translator"'
43     )
44   end
46   it 'should translate spaces then context " to describe "' do
47     @t.translate_line(
48       '  context "Translator"'
49     ).should eql(
50       '  describe "Translator"'
51     )
52   end
53   
54   it "should not translate context=foo" do
55     @t.translate_line('  context=foo').should eql('  context=foo')
56   end
58   it "should not translate context = foo" do
59     @t.translate_line('  context = foo').should eql('  context = foo')
60   end
62   it "should not translate context  =  foo" do
63     @t.translate_line('  context  =  foo').should eql('  context  =  foo')
64   end
65   
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)')
68   end
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')
72   end
74   it "should translate should_throw" do
75     @t.translate_line('lambda { self.call }.should_throw').should eql('lambda { self.call }.should throw_symbol')
76   end
78   it "should not translate 0.9 should_not" do
79     @t.translate_line('@target.should_not @matcher').should eql('@target.should_not @matcher')
80   end
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")')
84   end
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")')
88   end
89   
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')
92   end
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')
96   end
98   it "should translate be(expected) to equal(expected)" do
99     @t.translate_line('foo.should_be :cool').should eql('foo.should equal :cool')
100   end
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)')
104   end
106   it "should translate should_be <" do
107     @t.translate_line('3.should_be < 4').should eql('3.should be < 4')
108   end
110   it "should translate should_be <=" do
111     @t.translate_line('3.should_be <= 4').should eql('3.should be <= 4')
112   end
114   it "should translate should_be >=" do
115     @t.translate_line('4.should_be >= 3').should eql('4.should be >= 3')
116   end
118   it "should translate should_be >" do
119     @t.translate_line('4.should_be > 3').should eql('4.should be > 3')
120   end
122   it "should translate should_be_happy" do
123     @t.translate_line("4.should_be_happy").should eql("4.should be_happy")
124   end
125     
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/)")
128   end
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")
132   end
133    
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")
136   end
137     
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)'))
141   end
142   
143   it "should translate should_be_true" do
144     @t.translate_line("foo.should_be_true\n").should eql("foo.should be_true\n")
145   end
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")
152   end
153   
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")
157   end
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
162     @t.translate_line(
163       "lambda { sequence.parse('bar') }.should_throw :ZeroWidthParseSuccess\n"
164     ).should eql(
165       "lambda { sequence.parse('bar') }.should throw_symbol(:ZeroWidthParseSuccess)\n"
166     )
167   end
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
172     @t.translate_line(
173       "a.should_eql @local"
174     ).should eql(
175       "a.should eql(@local)"
176     )
177   end
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
182     @t.translate_line(
183       "@parslet.should_not_eql lambda { nil }.to_parseable"
184     ).should eql(
185       "@parslet.should_not eql(lambda { nil }.to_parseable)"
186     )
187   end
188   
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
192     @t.translate_line(
193       "results.should_be_kind_of SimpleASTLanguage::Identifier"
194     ).should eql(
195       "results.should be_kind_of(SimpleASTLanguage::Identifier)"
196     )
197   end
198     
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
202   #   @t.translate_line(
203   #     "lambda { @instance.foo = foo }.should_raise NoMethodError # no writer defined"
204   #   ).should eql(
205   #     "lambda { @instance.foo = foo }.should raise_error(NoMethodError) # no writer defined"
206   #   )
207   # end
209   it "should translate redirects" do
210     @t.translate_line(
211       "controller.should_redirect_to 'http://not_existing_domain_for_novalis.test.host/404.html'"
212     ).should eql(
213       "controller.should redirect_to('http://not_existing_domain_for_novalis.test.host/404.html')"
214     )
215   end
217   it "should translate :any_args" do
218     @t.translate_line(
219       "mock.should_receive(:foo).with(:any_args)"
220     ).should eql(
221       "mock.should_receive(:foo).with(any_args)"
222     )
223   end
225   it "should translate :anything" do
226     @t.translate_line(
227       "mock.should_receive(:foo).with(:anything)"
228     ).should eql(
229       "mock.should_receive(:foo).with(anything)"
230     )
231   end
233   it "should translate :boolean" do
234     @t.translate_line(
235       "mock.should_receive(:foo).with(:boolean)"
236     ).should eql(
237       "mock.should_receive(:foo).with(boolean)"
238     )
239   end
241   it "should translate :no_args" do
242     @t.translate_line(
243       "mock.should_receive(:foo).with(:no_args)"
244     ).should eql(
245       "mock.should_receive(:foo).with(no_args)"
246     )
247   end
249   it "should translate :numeric" do
250     @t.translate_line(
251       "mock.should_receive(:foo).with(:numeric)"
252     ).should eql(
253       "mock.should_receive(:foo).with(an_instance_of(Numeric))"
254     )
255   end
257   it "should translate :string" do
258     @t.translate_line(
259       "mock.should_receive(:foo).with(:string)"
260     ).should eql(
261       "mock.should_receive(:foo).with(an_instance_of(String))"
262     )
263   end