]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/translator_spec.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / spec / spec / translator_spec.rb
1 require File.dirname(__FILE__) + '/../spec_helper.rb'
2 require 'spec/translator'
3
4 describe "Translator" do
5   before do
6     @t = Spec::Translator.new
7   end
8   
9   it "should translate files" do
10     from = File.dirname(__FILE__) + '/..'
11     to = "#{Dir.tmpdir}/translated_specs"
12     @t.translate_dir(from, to)
13   end
14
15   it "should translate context_setup  do" do
16     @t.translate_line(
17       "context_setup  do\n"
18     ).should eql(
19       "before(:all)  do\n"
20     )
21   end
22
23   it "should translate context_setup  {foo}" do
24     @t.translate_line(
25       "context_setup  {foo}\n"
26     ).should eql(
27       "before(:all)  {foo}\n"
28     )
29   end
30   
31   it "should translate context ' to describe '" do
32     @t.translate_line(
33       "context 'Translator' do\n"
34     ).should eql(
35       "describe 'Translator' do\n"
36     )
37   end
38
39   it 'should translate context " to describe "' do
40     @t.translate_line(
41       'context "Translator"'
42     ).should eql(
43       'describe "Translator"'
44     )
45   end
46
47   it 'should translate spaces then context " to describe "' do
48     @t.translate_line(
49       '  context "Translator"'
50     ).should eql(
51       '  describe "Translator"'
52     )
53   end
54   
55   it "should not translate context=foo" do
56     @t.translate_line('  context=foo').should eql('  context=foo')
57   end
58
59   it "should not translate context = foo" do
60     @t.translate_line('  context = foo').should eql('  context = foo')
61   end
62
63   it "should not translate context  =  foo" do
64     @t.translate_line('  context  =  foo').should eql('  context  =  foo')
65   end
66   
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)')
69   end
70
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')
73   end
74
75   it "should translate should_throw" do
76     @t.translate_line('lambda { self.call }.should_throw').should eql('lambda { self.call }.should throw_symbol')
77   end
78
79   it "should not translate 0.9 should_not" do
80     @t.translate_line('@target.should_not @matcher').should eql('@target.should_not @matcher')
81   end
82
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")')
85   end
86
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")')
89   end
90   
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')
93   end
94
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')
97   end
98
99   it "should translate be(expected) to equal(expected)" do
100     @t.translate_line('foo.should_be :cool').should eql('foo.should equal :cool')
101   end
102
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)')
105   end
106
107   it "should translate should_be <" do
108     @t.translate_line('3.should_be < 4').should eql('3.should be < 4')
109   end
110
111   it "should translate should_be <=" do
112     @t.translate_line('3.should_be <= 4').should eql('3.should be <= 4')
113   end
114
115   it "should translate should_be >=" do
116     @t.translate_line('4.should_be >= 3').should eql('4.should be >= 3')
117   end
118
119   it "should translate should_be >" do
120     @t.translate_line('4.should_be > 3').should eql('4.should be > 3')
121   end
122
123   it "should translate should_be_happy" do
124     @t.translate_line("4.should_be_happy").should eql("4.should be_happy")
125   end
126     
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/)")
129   end
130
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")
133   end
134    
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")
137   end
138     
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)'))
142   end
143   
144   it "should translate should_be_true" do
145     @t.translate_line("foo.should_be_true\n").should eql("foo.should be_true\n")
146   end
147
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")
153   end
154   
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")
158   end
159
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
163     @t.translate_line(
164       "lambda { sequence.parse('bar') }.should_throw :ZeroWidthParseSuccess\n"
165     ).should eql(
166       "lambda { sequence.parse('bar') }.should throw_symbol(:ZeroWidthParseSuccess)\n"
167     )
168   end
169
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
173     @t.translate_line(
174       "a.should_eql @local"
175     ).should eql(
176       "a.should eql(@local)"
177     )
178   end
179
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
183     @t.translate_line(
184       "@parslet.should_not_eql lambda { nil }.to_parseable"
185     ).should eql(
186       "@parslet.should_not eql(lambda { nil }.to_parseable)"
187     )
188   end
189   
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
193     @t.translate_line(
194       "results.should_be_kind_of SimpleASTLanguage::Identifier"
195     ).should eql(
196       "results.should be_kind_of(SimpleASTLanguage::Identifier)"
197     )
198   end
199     
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
203   #   @t.translate_line(
204   #     "lambda { @instance.foo = foo }.should_raise NoMethodError # no writer defined"
205   #   ).should eql(
206   #     "lambda { @instance.foo = foo }.should raise_error(NoMethodError) # no writer defined"
207   #   )
208   # end
209
210   it "should translate redirects" do
211     @t.translate_line(
212       "controller.should_redirect_to 'http://not_existing_domain_for_novalis.test.host/404.html'"
213     ).should eql(
214       "controller.should redirect_to('http://not_existing_domain_for_novalis.test.host/404.html')"
215     )
216   end
217
218   it "should translate :any_args" do
219     @t.translate_line(
220       "mock.should_receive(:foo).with(:any_args)"
221     ).should eql(
222       "mock.should_receive(:foo).with(any_args)"
223     )
224   end
225
226   it "should translate :anything" do
227     @t.translate_line(
228       "mock.should_receive(:foo).with(:anything)"
229     ).should eql(
230       "mock.should_receive(:foo).with(anything)"
231     )
232   end
233
234   it "should translate :boolean" do
235     @t.translate_line(
236       "mock.should_receive(:foo).with(:boolean)"
237     ).should eql(
238       "mock.should_receive(:foo).with(boolean)"
239     )
240   end
241
242   it "should translate :no_args" do
243     @t.translate_line(
244       "mock.should_receive(:foo).with(:no_args)"
245     ).should eql(
246       "mock.should_receive(:foo).with(no_args)"
247     )
248   end
249
250   it "should translate :numeric" do
251     @t.translate_line(
252       "mock.should_receive(:foo).with(:numeric)"
253     ).should eql(
254       "mock.should_receive(:foo).with(an_instance_of(Numeric))"
255     )
256   end
257
258   it "should translate :string" do
259     @t.translate_line(
260       "mock.should_receive(:foo).with(:string)"
261     ).should eql(
262       "mock.should_receive(:foo).with(an_instance_of(String))"
263     )
264   end
265 end