Skip to content

Commit a0cb1b4

Browse files
committed
Convert specs to RSpec 3.0.1 syntax with Transpec
This conversion is done by Transpec 2.2.5 with the following command: transpec * 34 conversions from: obj.should to: expect(obj).to * 27 conversions from: obj.should_receive(:message) to: expect(obj).to receive(:message) * 18 conversions from: == expected to: eq(expected) * 4 conversions from: obj.should_not to: expect(obj).not_to * 4 conversions from: obj.stub(:message) to: allow(obj).to receive(:message) For more details: https://github.com/yujinakayama/transpec#supported-conversions
1 parent 70e82ad commit a0cb1b4

File tree

4 files changed

+77
-77
lines changed

4 files changed

+77
-77
lines changed

spec/annotate/annotate_models_spec.rb

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ def mock_column(name, type, options={})
3030
double("Column", stubs)
3131
end
3232

33-
it { AnnotateModels.quote(nil).should eql("NULL") }
34-
it { AnnotateModels.quote(true).should eql("TRUE") }
35-
it { AnnotateModels.quote(false).should eql("FALSE") }
36-
it { AnnotateModels.quote(25).should eql("25") }
37-
it { AnnotateModels.quote(25.6).should eql("25.6") }
38-
it { AnnotateModels.quote(1e-20).should eql("1.0e-20") }
33+
it { expect(AnnotateModels.quote(nil)).to eql("NULL") }
34+
it { expect(AnnotateModels.quote(true)).to eql("TRUE") }
35+
it { expect(AnnotateModels.quote(false)).to eql("FALSE") }
36+
it { expect(AnnotateModels.quote(25)).to eql("25") }
37+
it { expect(AnnotateModels.quote(25.6)).to eql("25.6") }
38+
it { expect(AnnotateModels.quote(1e-20)).to eql("1.0e-20") }
3939

4040
it "should get schema info" do
4141
klass = mock_class(:users, :id, [
4242
mock_column(:id, :integer),
4343
mock_column(:name, :string, :limit => 50)
4444
])
4545

46-
AnnotateModels.get_schema_info(klass, "Schema Info").should eql(<<-EOS)
46+
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS)
4747
# Schema Info
4848
#
4949
# Table name: users
@@ -60,7 +60,7 @@ def mock_column(name, type, options={})
6060
mock_column(:name, :string, :limit => 50)
6161
])
6262

63-
AnnotateModels.get_schema_info(klass, "Schema Info").should eql(<<-EOS)
63+
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS)
6464
# Schema Info
6565
#
6666
# Table name: users
@@ -78,7 +78,7 @@ def mock_column(name, type, options={})
7878
mock_column(:name, :string, :limit => 50)
7979
])
8080

81-
AnnotateModels.get_schema_info(klass, "Schema Info").should eql(<<-EOS)
81+
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS)
8282
# Schema Info
8383
#
8484
# Table name: users
@@ -95,7 +95,7 @@ def mock_column(name, type, options={})
9595
mock_column(:name, :enum, :limit => [:enum1, :enum2])
9696
])
9797

98-
AnnotateModels.get_schema_info(klass, "Schema Info").should eql(<<-EOS)
98+
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS)
9999
# Schema Info
100100
#
101101
# Table name: users
@@ -111,7 +111,7 @@ def mock_column(name, type, options={})
111111
mock_column(:id, :integer),
112112
mock_column(:name, :string, :limit => 50)
113113
])
114-
AnnotateModels.get_schema_info(klass, AnnotateModels::PREFIX, :format_rdoc => true).should eql(<<-EOS)
114+
expect(AnnotateModels.get_schema_info(klass, AnnotateModels::PREFIX, :format_rdoc => true)).to eql(<<-EOS)
115115
# #{AnnotateModels::PREFIX}
116116
#
117117
# Table name: users
@@ -148,8 +148,8 @@ def create(file, body="hi")
148148
def check_class_name(file, class_name)
149149
klass = AnnotateModels.get_model_class(file)
150150

151-
klass.should_not == nil
152-
klass.name.should == class_name
151+
expect(klass).not_to eq(nil)
152+
expect(klass.name).to eq(class_name)
153153
end
154154

155155
before :each do
@@ -283,9 +283,9 @@ class FooWithKnownMacro < ActiveRecord::Base
283283
has_many :yah
284284
end
285285
EOS
286-
capturing(:stderr) do
286+
expect(capturing(:stderr) do
287287
check_class_name 'foo_with_known_macro.rb', 'FooWithKnownMacro'
288-
end.should == ""
288+
end).to eq("")
289289
end
290290

291291
it "should not require model files twice" do
@@ -298,9 +298,9 @@ class LoadedClass < ActiveRecord::Base
298298
Kernel.load "#{path}.rb"
299299
expect(Kernel).not_to receive(:require).with(path)
300300

301-
capturing(:stderr) {
301+
expect(capturing(:stderr) {
302302
check_class_name 'loaded_class.rb', 'LoadedClass'
303-
}.should_not include("warning: already initialized constant LoadedClass::CONSTANT")
303+
}).not_to include("warning: already initialized constant LoadedClass::CONSTANT")
304304
end
305305
end
306306

@@ -340,7 +340,7 @@ class Foo < ActiveRecord::Base
340340

341341
AnnotateModels.remove_annotation_of_file(path)
342342

343-
content(path).should == <<-EOS
343+
expect(content(path)).to eq <<-EOS
344344
class Foo < ActiveRecord::Base
345345
end
346346
EOS
@@ -364,7 +364,7 @@ class Foo < ActiveRecord::Base
364364

365365
AnnotateModels.remove_annotation_of_file(path)
366366

367-
content(path).should == <<-EOS
367+
expect(content(path)).to eq <<-EOS
368368
class Foo < ActiveRecord::Base
369369
end
370370
EOS
@@ -417,17 +417,17 @@ def encoding_comments_list_each
417417

418418
it "should put annotation before class if :position == 'before'" do
419419
annotate_one_file :position => "before"
420-
File.read(@model_file_name).should == "#{@schema_info}\n#{@file_content}"
420+
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
421421
end
422422

423423
it "should put annotation before class if :position => :before" do
424424
annotate_one_file :position => :before
425-
File.read(@model_file_name).should == "#{@schema_info}\n#{@file_content}"
425+
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
426426
end
427427

428428
it "should put annotation after class if :position => :after" do
429429
annotate_one_file :position => :after
430-
File.read(@model_file_name).should == "#{@file_content}\n#{@schema_info}"
430+
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
431431
end
432432

433433
describe "with existing annotation => :before" do
@@ -440,17 +440,17 @@ def encoding_comments_list_each
440440

441441
it "should retain current position" do
442442
annotate_one_file
443-
File.read(@model_file_name).should == "#{@schema_info}\n#{@file_content}"
443+
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
444444
end
445445

446446
it "should retain current position even when :position is changed to :after" do
447447
annotate_one_file :position => :after
448-
File.read(@model_file_name).should == "#{@schema_info}\n#{@file_content}"
448+
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
449449
end
450450

451451
it "should change position to :after when :force => true" do
452452
annotate_one_file :position => :after, :force => true
453-
File.read(@model_file_name).should == "#{@file_content}\n#{@schema_info}"
453+
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
454454
end
455455
end
456456

@@ -464,17 +464,17 @@ def encoding_comments_list_each
464464

465465
it "should retain current position" do
466466
annotate_one_file
467-
File.read(@model_file_name).should == "#{@file_content}\n#{@schema_info}"
467+
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
468468
end
469469

470470
it "should retain current position even when :position is changed to :before" do
471471
annotate_one_file :position => :before
472-
File.read(@model_file_name).should == "#{@file_content}\n#{@schema_info}"
472+
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
473473
end
474474

475475
it "should change position to :before when :force => true" do
476476
annotate_one_file :position => :before, :force => true
477-
File.read(@model_file_name).should == "#{@schema_info}\n#{@file_content}"
477+
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
478478
end
479479
end
480480

@@ -496,7 +496,7 @@ class Foo::User < ActiveRecord::Base
496496
])
497497
schema_info = AnnotateModels.get_schema_info(klass, "== Schema Info")
498498
AnnotateModels.annotate_one_file(model_file_name, schema_info, :position => :before)
499-
File.read(model_file_name).should == "#{schema_info}\n#{file_content}"
499+
expect(File.read(model_file_name)).to eq("#{schema_info}\n#{file_content}")
500500
end
501501

502502
it "should not touch encoding comments" do
@@ -509,13 +509,13 @@ class User < ActiveRecord::Base
509509

510510
annotate_one_file :position => :before
511511

512-
File.open(@model_file_name, &:readline).should == "#{encoding_comment}\n"
512+
expect(File.open(@model_file_name, &:readline)).to eq("#{encoding_comment}\n")
513513
end
514514
end
515515

516516
describe "if a file can't be annotated" do
517517
before do
518-
AnnotateModels.stub(:get_loaded_model).with('user').and_return(nil)
518+
allow(AnnotateModels).to receive(:get_loaded_model).with('user').and_return(nil)
519519

520520
write_model('user.rb', <<-EOS)
521521
class User < ActiveRecord::Base
@@ -525,27 +525,27 @@ class User < ActiveRecord::Base
525525
end
526526

527527
it "displays an error message" do
528-
capturing(:stdout) {
528+
expect(capturing(:stdout) {
529529
AnnotateModels.do_annotations :model_dir => @model_dir, :is_rake => true
530-
}.should include("Unable to annotate user.rb: oops")
530+
}).to include("Unable to annotate user.rb: oops")
531531
end
532532

533533
it "displays the full stack trace with --trace" do
534-
capturing(:stdout) {
534+
expect(capturing(:stdout) {
535535
AnnotateModels.do_annotations :model_dir => @model_dir, :trace => true, :is_rake => true
536-
}.should include("/spec/annotate/annotate_models_spec.rb:")
536+
}).to include("/spec/annotate/annotate_models_spec.rb:")
537537
end
538538

539539
it "omits the full stack trace without --trace" do
540-
capturing(:stdout) {
540+
expect(capturing(:stdout) {
541541
AnnotateModels.do_annotations :model_dir => @model_dir, :trace => false, :is_rake => true
542-
}.should_not include("/spec/annotate/annotate_models_spec.rb:")
542+
}).not_to include("/spec/annotate/annotate_models_spec.rb:")
543543
end
544544
end
545545

546546
describe "if a file can't be deannotated" do
547547
before do
548-
AnnotateModels.stub(:get_loaded_model).with('user').and_return(nil)
548+
allow(AnnotateModels).to receive(:get_loaded_model).with('user').and_return(nil)
549549

550550
write_model('user.rb', <<-EOS)
551551
class User < ActiveRecord::Base
@@ -555,38 +555,38 @@ class User < ActiveRecord::Base
555555
end
556556

557557
it "displays an error message" do
558-
capturing(:stdout) {
558+
expect(capturing(:stdout) {
559559
AnnotateModels.remove_annotations :model_dir => @model_dir, :is_rake => true
560-
}.should include("Unable to deannotate user.rb: oops")
560+
}).to include("Unable to deannotate user.rb: oops")
561561
end
562562

563563
it "displays the full stack trace" do
564-
capturing(:stdout) {
564+
expect(capturing(:stdout) {
565565
AnnotateModels.remove_annotations :model_dir => @model_dir, :trace => true, :is_rake => true
566-
}.should include("/user.rb:2:in `<class:User>'")
566+
}).to include("/user.rb:2:in `<class:User>'")
567567
end
568568

569569
it "omits the full stack trace without --trace" do
570-
capturing(:stdout) {
570+
expect(capturing(:stdout) {
571571
AnnotateModels.remove_annotations :model_dir => @model_dir, :trace => false, :is_rake => true
572-
}.should_not include("/user.rb:2:in `<class:User>'")
572+
}).not_to include("/user.rb:2:in `<class:User>'")
573573
end
574574
end
575575
end
576576

577577
describe '.annotate_model_file' do
578578
before do
579579
class Foo < ActiveRecord::Base; end;
580-
AnnotateModels.stub(:get_model_class).with('foo.rb') { Foo }
581-
Foo.stub(:table_exists?) { false }
580+
allow(AnnotateModels).to receive(:get_model_class).with('foo.rb') { Foo }
581+
allow(Foo).to receive(:table_exists?) { false }
582582
end
583583

584584
after { Object.send :remove_const, 'Foo' }
585585

586586
it 'skips attempt to annotate if no table exists for model' do
587587
annotate_model_file = AnnotateModels.annotate_model_file([], 'foo.rb', nil, nil)
588588

589-
annotate_model_file.should eq nil
589+
expect(annotate_model_file).to eq nil
590590
end
591591
end
592592
end

spec/annotate/annotate_routes_spec.rb

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ def mock_file(stubs={})
88
end
99

1010
it "should check if routes.rb exists" do
11-
File.should_receive(:exists?).with("config/routes.rb").and_return(false)
12-
AnnotateRoutes.should_receive(:puts).with("Can`t find routes.rb")
11+
expect(File).to receive(:exists?).with("config/routes.rb").and_return(false)
12+
expect(AnnotateRoutes).to receive(:puts).with("Can`t find routes.rb")
1313
AnnotateRoutes.do_annotations
1414
end
1515

1616
describe "When Annotating, with older Rake Versions" do
1717

1818
before(:each) do
19-
File.should_receive(:exists?).with("config/routes.rb").and_return(true)
20-
AnnotateRoutes.should_receive(:`).with("rake routes").and_return("(in /bad/line)\ngood line")
21-
File.should_receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
22-
AnnotateRoutes.should_receive(:puts).with("Route file annotated.")
19+
expect(File).to receive(:exists?).with("config/routes.rb").and_return(true)
20+
expect(AnnotateRoutes).to receive(:`).with("rake routes").and_return("(in /bad/line)\ngood line")
21+
expect(File).to receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
22+
expect(AnnotateRoutes).to receive(:puts).with("Route file annotated.")
2323
end
2424

2525
it "should annotate and add a newline!" do
26-
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
27-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/)
26+
expect(File).to receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
27+
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/)
2828
AnnotateRoutes.do_annotations
2929
end
3030

3131
it "should not add a newline if there are empty lines" do
32-
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo\n")
33-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/)
32+
expect(File).to receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo\n")
33+
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/)
3434
AnnotateRoutes.do_annotations
3535
end
3636

@@ -39,27 +39,27 @@ def mock_file(stubs={})
3939
describe "When Annotating, with newer Rake Versions" do
4040

4141
before(:each) do
42-
File.should_receive(:exists?).with("config/routes.rb").and_return(true)
43-
AnnotateRoutes.should_receive(:`).with("rake routes").and_return("another good line\ngood line")
44-
File.should_receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
45-
AnnotateRoutes.should_receive(:puts).with("Route file annotated.")
42+
expect(File).to receive(:exists?).with("config/routes.rb").and_return(true)
43+
expect(AnnotateRoutes).to receive(:`).with("rake routes").and_return("another good line\ngood line")
44+
expect(File).to receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
45+
expect(AnnotateRoutes).to receive(:puts).with("Route file annotated.")
4646
end
4747

4848
it "should annotate and add a newline!" do
49-
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
50-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/)
49+
expect(File).to receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
50+
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/)
5151
AnnotateRoutes.do_annotations
5252
end
5353

5454
it "should not add a newline if there are empty lines" do
55-
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo\n")
56-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/)
55+
expect(File).to receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo\n")
56+
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/)
5757
AnnotateRoutes.do_annotations
5858
end
5959

6060
it "should add a timestamp when :timestamp is passed" do
61-
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
62-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/)
61+
expect(File).to receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
62+
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/)
6363
AnnotateRoutes.do_annotations :timestamp => true
6464
end
6565

@@ -68,20 +68,20 @@ def mock_file(stubs={})
6868
describe "When Removing Annotation" do
6969

7070
before(:each) do
71-
File.should_receive(:exists?).with("config/routes.rb").and_return(true)
72-
File.should_receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
73-
AnnotateRoutes.should_receive(:puts).with("Removed annotations from routes file.")
71+
expect(File).to receive(:exists?).with("config/routes.rb").and_return(true)
72+
expect(File).to receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
73+
expect(AnnotateRoutes).to receive(:puts).with("Removed annotations from routes file.")
7474
end
7575

7676
it "should remove trailing annotation and trim trailing newlines, but leave leading newlines alone" do
77-
File.should_receive(:read).with("config/routes.rb").and_return("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n# == Route Map\n#\n# another good line\n# good line\n")
78-
@mock_file.should_receive(:puts).with(/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n/)
77+
expect(File).to receive(:read).with("config/routes.rb").and_return("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n# == Route Map\n#\n# another good line\n# good line\n")
78+
expect(@mock_file).to receive(:puts).with(/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n/)
7979
AnnotateRoutes.remove_annotations
8080
end
8181

8282
it "should remove prepended annotation and trim leading newlines, but leave trailing newlines alone" do
83-
File.should_receive(:read).with("config/routes.rb").and_return("# == Route Map\n#\n# another good line\n# good line\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n")
84-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n/)
83+
expect(File).to receive(:read).with("config/routes.rb").and_return("# == Route Map\n#\n# another good line\n# good line\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n")
84+
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n/)
8585
AnnotateRoutes.remove_annotations
8686
end
8787

0 commit comments

Comments
 (0)