@@ -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
344344class Foo < ActiveRecord::Base
345345end
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
368368class Foo < ActiveRecord::Base
369369end
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
592592end
0 commit comments