@@ -30,20 +30,20 @@ def mock_column(name, type, options={})
30
30
double ( "Column" , stubs )
31
31
end
32
32
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" ) }
39
39
40
40
it "should get schema info" do
41
41
klass = mock_class ( :users , :id , [
42
42
mock_column ( :id , :integer ) ,
43
43
mock_column ( :name , :string , :limit => 50 )
44
44
] )
45
45
46
- AnnotateModels . get_schema_info ( klass , "Schema Info" ) . should eql ( <<-EOS )
46
+ expect ( AnnotateModels . get_schema_info ( klass , "Schema Info" ) ) . to eql ( <<-EOS )
47
47
# Schema Info
48
48
#
49
49
# Table name: users
@@ -60,7 +60,7 @@ def mock_column(name, type, options={})
60
60
mock_column ( :name , :string , :limit => 50 )
61
61
] )
62
62
63
- AnnotateModels . get_schema_info ( klass , "Schema Info" ) . should eql ( <<-EOS )
63
+ expect ( AnnotateModels . get_schema_info ( klass , "Schema Info" ) ) . to eql ( <<-EOS )
64
64
# Schema Info
65
65
#
66
66
# Table name: users
@@ -78,7 +78,7 @@ def mock_column(name, type, options={})
78
78
mock_column ( :name , :string , :limit => 50 )
79
79
] )
80
80
81
- AnnotateModels . get_schema_info ( klass , "Schema Info" ) . should eql ( <<-EOS )
81
+ expect ( AnnotateModels . get_schema_info ( klass , "Schema Info" ) ) . to eql ( <<-EOS )
82
82
# Schema Info
83
83
#
84
84
# Table name: users
@@ -95,7 +95,7 @@ def mock_column(name, type, options={})
95
95
mock_column ( :name , :enum , :limit => [ :enum1 , :enum2 ] )
96
96
] )
97
97
98
- AnnotateModels . get_schema_info ( klass , "Schema Info" ) . should eql ( <<-EOS )
98
+ expect ( AnnotateModels . get_schema_info ( klass , "Schema Info" ) ) . to eql ( <<-EOS )
99
99
# Schema Info
100
100
#
101
101
# Table name: users
@@ -111,7 +111,7 @@ def mock_column(name, type, options={})
111
111
mock_column ( :id , :integer ) ,
112
112
mock_column ( :name , :string , :limit => 50 )
113
113
] )
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 )
115
115
# #{ AnnotateModels ::PREFIX }
116
116
#
117
117
# Table name: users
@@ -148,8 +148,8 @@ def create(file, body="hi")
148
148
def check_class_name ( file , class_name )
149
149
klass = AnnotateModels . get_model_class ( file )
150
150
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 )
153
153
end
154
154
155
155
before :each do
@@ -283,9 +283,9 @@ class FooWithKnownMacro < ActiveRecord::Base
283
283
has_many :yah
284
284
end
285
285
EOS
286
- capturing ( :stderr ) do
286
+ expect ( capturing ( :stderr ) do
287
287
check_class_name 'foo_with_known_macro.rb' , 'FooWithKnownMacro'
288
- end . should == ""
288
+ end ) . to eq ( "" )
289
289
end
290
290
291
291
it "should not require model files twice" do
@@ -298,9 +298,9 @@ class LoadedClass < ActiveRecord::Base
298
298
Kernel . load "#{ path } .rb"
299
299
expect ( Kernel ) . not_to receive ( :require ) . with ( path )
300
300
301
- capturing ( :stderr ) {
301
+ expect ( capturing ( :stderr ) {
302
302
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" )
304
304
end
305
305
end
306
306
@@ -340,7 +340,7 @@ class Foo < ActiveRecord::Base
340
340
341
341
AnnotateModels . remove_annotation_of_file ( path )
342
342
343
- content ( path ) . should == <<-EOS
343
+ expect ( content ( path ) ) . to eq <<-EOS
344
344
class Foo < ActiveRecord::Base
345
345
end
346
346
EOS
@@ -364,7 +364,7 @@ class Foo < ActiveRecord::Base
364
364
365
365
AnnotateModels . remove_annotation_of_file ( path )
366
366
367
- content ( path ) . should == <<-EOS
367
+ expect ( content ( path ) ) . to eq <<-EOS
368
368
class Foo < ActiveRecord::Base
369
369
end
370
370
EOS
@@ -417,17 +417,17 @@ def encoding_comments_list_each
417
417
418
418
it "should put annotation before class if :position == 'before'" do
419
419
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 } " )
421
421
end
422
422
423
423
it "should put annotation before class if :position => :before" do
424
424
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 } " )
426
426
end
427
427
428
428
it "should put annotation after class if :position => :after" do
429
429
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 } " )
431
431
end
432
432
433
433
describe "with existing annotation => :before" do
@@ -440,17 +440,17 @@ def encoding_comments_list_each
440
440
441
441
it "should retain current position" do
442
442
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 } " )
444
444
end
445
445
446
446
it "should retain current position even when :position is changed to :after" do
447
447
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 } " )
449
449
end
450
450
451
451
it "should change position to :after when :force => true" do
452
452
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 } " )
454
454
end
455
455
end
456
456
@@ -464,17 +464,17 @@ def encoding_comments_list_each
464
464
465
465
it "should retain current position" do
466
466
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 } " )
468
468
end
469
469
470
470
it "should retain current position even when :position is changed to :before" do
471
471
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 } " )
473
473
end
474
474
475
475
it "should change position to :before when :force => true" do
476
476
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 } " )
478
478
end
479
479
end
480
480
@@ -496,7 +496,7 @@ class Foo::User < ActiveRecord::Base
496
496
] )
497
497
schema_info = AnnotateModels . get_schema_info ( klass , "== Schema Info" )
498
498
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 } " )
500
500
end
501
501
502
502
it "should not touch encoding comments" do
@@ -509,13 +509,13 @@ class User < ActiveRecord::Base
509
509
510
510
annotate_one_file :position => :before
511
511
512
- File . open ( @model_file_name , &:readline ) . should == "#{ encoding_comment } \n "
512
+ expect ( File . open ( @model_file_name , &:readline ) ) . to eq ( "#{ encoding_comment } \n " )
513
513
end
514
514
end
515
515
516
516
describe "if a file can't be annotated" do
517
517
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 )
519
519
520
520
write_model ( 'user.rb' , <<-EOS )
521
521
class User < ActiveRecord::Base
@@ -525,27 +525,27 @@ class User < ActiveRecord::Base
525
525
end
526
526
527
527
it "displays an error message" do
528
- capturing ( :stdout ) {
528
+ expect ( capturing ( :stdout ) {
529
529
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" )
531
531
end
532
532
533
533
it "displays the full stack trace with --trace" do
534
- capturing ( :stdout ) {
534
+ expect ( capturing ( :stdout ) {
535
535
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:" )
537
537
end
538
538
539
539
it "omits the full stack trace without --trace" do
540
- capturing ( :stdout ) {
540
+ expect ( capturing ( :stdout ) {
541
541
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:" )
543
543
end
544
544
end
545
545
546
546
describe "if a file can't be deannotated" do
547
547
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 )
549
549
550
550
write_model ( 'user.rb' , <<-EOS )
551
551
class User < ActiveRecord::Base
@@ -555,38 +555,38 @@ class User < ActiveRecord::Base
555
555
end
556
556
557
557
it "displays an error message" do
558
- capturing ( :stdout ) {
558
+ expect ( capturing ( :stdout ) {
559
559
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" )
561
561
end
562
562
563
563
it "displays the full stack trace" do
564
- capturing ( :stdout ) {
564
+ expect ( capturing ( :stdout ) {
565
565
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>'" )
567
567
end
568
568
569
569
it "omits the full stack trace without --trace" do
570
- capturing ( :stdout ) {
570
+ expect ( capturing ( :stdout ) {
571
571
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>'" )
573
573
end
574
574
end
575
575
end
576
576
577
577
describe '.annotate_model_file' do
578
578
before do
579
579
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 }
582
582
end
583
583
584
584
after { Object . send :remove_const , 'Foo' }
585
585
586
586
it 'skips attempt to annotate if no table exists for model' do
587
587
annotate_model_file = AnnotateModels . annotate_model_file ( [ ] , 'foo.rb' , nil , nil )
588
588
589
- annotate_model_file . should eq nil
589
+ expect ( annotate_model_file ) . to eq nil
590
590
end
591
591
end
592
592
end
0 commit comments