4
4
require 'annotate/active_record_patch'
5
5
require 'active_support/core_ext/string'
6
6
require 'files'
7
+ require 'tmpdir'
7
8
8
9
describe AnnotateModels do
9
10
MAGIC_COMMENTS = [
@@ -1781,7 +1782,6 @@ def mock_column(name, type, options = {})
1781
1782
1782
1783
describe '.get_model_class' do
1783
1784
before :all do
1784
- require 'tmpdir'
1785
1785
AnnotateModels . model_dir = Dir . mktmpdir ( 'annotate_models' )
1786
1786
end
1787
1787
@@ -2137,7 +2137,6 @@ class Foo
2137
2137
end
2138
2138
2139
2139
let :tmpdir do
2140
- require 'tmpdir'
2141
2140
Dir . mktmpdir ( 'annotate_models' )
2142
2141
end
2143
2142
@@ -2659,21 +2658,13 @@ class User < ActiveRecord::Base
2659
2658
end
2660
2659
2661
2660
it 'displays just the error message with trace disabled (default)' do
2662
- error_output = capturing ( :stderr ) do
2663
- AnnotateModels . do_annotations model_dir : @model_dir , is_rake : true
2664
- end
2665
-
2666
- expect ( error_output ) . to include ( "Unable to annotate #{ @model_dir } /user.rb: oops" )
2667
- expect ( error_output ) . not_to include ( '/spec/annotate/annotate_models_spec.rb:' )
2661
+ expect { AnnotateModels . do_annotations model_dir : @model_dir , is_rake : true } . to output ( a_string_including ( "Unable to annotate #{ @model_dir } /user.rb: oops" ) ) . to_stderr
2662
+ expect { AnnotateModels . do_annotations model_dir : @model_dir , is_rake : true } . not_to output ( a_string_including ( '/spec/annotate/annotate_models_spec.rb:' ) ) . to_stderr
2668
2663
end
2669
2664
2670
2665
it 'displays the error message and stacktrace with trace enabled' do
2671
- error_output = capturing ( :stderr ) do
2672
- AnnotateModels . do_annotations model_dir : @model_dir , is_rake : true , trace : true
2673
- end
2674
-
2675
- expect ( error_output ) . to include ( "Unable to annotate #{ @model_dir } /user.rb: oops" )
2676
- expect ( error_output ) . to include ( '/spec/lib/annotate/annotate_models_spec.rb:' )
2666
+ expect { AnnotateModels . do_annotations model_dir : @model_dir , is_rake : true , trace : true } . to output ( a_string_including ( "Unable to annotate #{ @model_dir } /user.rb: oops" ) ) . to_stderr
2667
+ expect { AnnotateModels . do_annotations model_dir : @model_dir , is_rake : true , trace : true } . to output ( a_string_including ( '/spec/lib/annotate/annotate_models_spec.rb:' ) ) . to_stderr
2677
2668
end
2678
2669
end
2679
2670
@@ -2689,21 +2680,13 @@ class User < ActiveRecord::Base
2689
2680
end
2690
2681
2691
2682
it 'displays just the error message with trace disabled (default)' do
2692
- error_output = capturing ( :stderr ) do
2693
- AnnotateModels . remove_annotations model_dir : @model_dir , is_rake : true
2694
- end
2695
-
2696
- expect ( error_output ) . to include ( "Unable to deannotate #{ @model_dir } /user.rb: oops" )
2697
- expect ( error_output ) . not_to include ( "/user.rb:2:in `<class:User>'" )
2683
+ expect { AnnotateModels . remove_annotations model_dir : @model_dir , is_rake : true } . to output ( a_string_including ( "Unable to deannotate #{ @model_dir } /user.rb: oops" ) ) . to_stderr
2684
+ expect { AnnotateModels . remove_annotations model_dir : @model_dir , is_rake : true } . not_to output ( a_string_including ( "/user.rb:2:in `<class:User>'" ) ) . to_stderr
2698
2685
end
2699
2686
2700
2687
it 'displays the error message and stacktrace with trace enabled' do
2701
- error_output = capturing ( :stderr ) do
2702
- AnnotateModels . remove_annotations model_dir : @model_dir , is_rake : true , trace : true
2703
- end
2704
-
2705
- expect ( error_output ) . to include ( "Unable to deannotate #{ @model_dir } /user.rb: oops" )
2706
- expect ( error_output ) . to include ( "/user.rb:2:in `<class:User>'" )
2688
+ expect { AnnotateModels . remove_annotations model_dir : @model_dir , is_rake : true , trace : true } . to output ( a_string_including ( "Unable to deannotate #{ @model_dir } /user.rb: oops" ) ) . to_stderr
2689
+ expect { AnnotateModels . remove_annotations model_dir : @model_dir , is_rake : true , trace : true } . to output ( a_string_including ( "/user.rb:2:in `<class:User>'" ) ) . to_stderr
2707
2690
end
2708
2691
end
2709
2692
0 commit comments