generator-spec 0.4.5 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. data/README.markdown +58 -46
  2. data/VERSION +1 -1
  3. data/generator-spec.gemspec +83 -14
  4. data/lib/generator_spec/helpers/migration_helper.rb +2 -2
  5. data/lib/generator_spec/main.rb +5 -0
  6. data/lib/generator_spec/matchers/content/content_matcher.rb +84 -4
  7. data/lib/generator_spec/matchers/content/have_block.rb +24 -22
  8. data/lib/generator_spec/matchers/content/have_call.rb +21 -13
  9. data/lib/generator_spec/matchers/content/have_calls.rb +32 -26
  10. data/lib/generator_spec/matchers/content/have_class_self.rb +40 -0
  11. data/lib/generator_spec/matchers/content/have_method.rb +31 -24
  12. data/lib/generator_spec/matchers/content/have_module.rb +49 -19
  13. data/lib/generator_spec/matchers/content/have_region.rb +9 -10
  14. data/lib/generator_spec/matchers/content/have_subclass.rb +9 -15
  15. data/lib/generator_spec/matchers/content/include_module.rb +9 -10
  16. data/lib/generator_spec/matchers/content/inherit_from.rb +10 -10
  17. data/lib/generator_spec/matchers/file/generate_file.rb +4 -11
  18. data/lib/generator_spec/matchers/file/generate_migration.rb +1 -5
  19. data/lib/generator_spec/matchers/file/have_file.rb +115 -0
  20. data/lib/generator_spec/rails_helpers/rails_controller.rb +30 -32
  21. data/lib/generator_spec/rails_helpers/rails_model.rb +2 -1
  22. data/lib/generator_spec/rails_helpers/rails_view.rb +19 -3
  23. data/spec/generator_spec/{controller_generator_spec.rb → generators/controller_generator_spec.rb} +0 -0
  24. data/spec/generator_spec/{helper_generator_spec.rb → generators/helper_generator_spec.rb} +0 -0
  25. data/spec/generator_spec/{migration_generator_spec.rb → generators/migration_generator_spec.rb} +0 -0
  26. data/spec/generator_spec/{model_generator_spec.rb → generators/model_generator_spec.rb} +0 -0
  27. data/spec/generator_spec/{observer_generator_spec.rb → generators/observer_generator_spec.rb} +0 -0
  28. data/spec/generator_spec/{view_generator_spec.rb → generators/view_generator_spec.rb} +0 -0
  29. data/spec/generator_spec/matchers/content/class_self_spec.rb +32 -0
  30. data/spec/generator_spec/matchers/content/have_block_spec.rb +57 -0
  31. data/spec/generator_spec/matchers/content/have_call_spec.rb +39 -0
  32. data/spec/generator_spec/matchers/content/have_calls_spec.rb +50 -0
  33. data/spec/generator_spec/matchers/content/have_class_spec.rb +34 -0
  34. data/spec/generator_spec/matchers/content/have_method_spec.rb +52 -0
  35. data/spec/generator_spec/matchers/content/have_module_spec.rb +34 -0
  36. data/spec/generator_spec/matchers/content/have_region_spec.rb +56 -0
  37. data/spec/generator_spec/matchers/content/have_subclass_spec.rb +34 -0
  38. data/spec/generator_spec/matchers/content/include_module_spec.rb +36 -0
  39. data/spec/generator_spec/matchers/content/inherit_from_spec.rb +34 -0
  40. data/spec/generator_spec/matchers/file/directory_spec.rb +0 -0
  41. data/spec/generator_spec/matchers/file/file_spec.rb +0 -0
  42. data/spec/generator_spec/matchers/file/migration_spec.rb +0 -0
  43. data/spec/generator_spec/matchers/migration/have_column_spec.rb +0 -0
  44. data/spec/generator_spec/matchers/migration/have_index_spec.rb +0 -0
  45. data/spec/generator_spec/matchers/migration/have_table_spec.rb +0 -0
  46. data/spec/generator_spec/matchers/migration/have_tbl_column_spec.rb +0 -0
  47. data/spec/generator_spec/matchers/migration/have_up_down_spec.rb +0 -0
  48. data/spec/generator_spec/matchers/rails/controller_matcher_spec.rb +26 -0
  49. data/spec/generator_spec/matchers/rails/helper_matcher_spec.rb +26 -0
  50. data/spec/generator_spec/matchers/rails/mailer_matcher_spec.rb +24 -0
  51. data/spec/generator_spec/matchers/rails/model_matcher_spec.rb +31 -0
  52. data/spec/generator_spec/matchers/rails/observer_matcher_spec.rb +19 -0
  53. data/spec/generator_spec/matchers/rails/view_matcher_spec.rb +23 -0
  54. data/spec/generator_spec/rails_helpers/rails_app_spec.rb +0 -0
  55. data/spec/generator_spec/rails_helpers/rails_controller_spec.rb +0 -0
  56. data/spec/generator_spec/rails_helpers/rails_helper_spec.rb +0 -0
  57. data/spec/generator_spec/rails_helpers/rails_mailer_spec.rb +0 -0
  58. data/spec/generator_spec/rails_helpers/rails_migration_spec.rb +0 -0
  59. data/spec/generator_spec/rails_helpers/rails_model_spec.rb +0 -0
  60. data/spec/generator_spec/rails_helpers/rails_observer_spec.rb +0 -0
  61. data/spec/generator_spec/rails_helpers/rails_orm_spec.rb +0 -0
  62. data/spec/generator_spec/rails_helpers/rails_view_spec.rb +0 -0
  63. metadata +84 -15
  64. data/lib/generator_spec/matchers/content/have_class.rb +0 -53
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'block matcher' do
4
+ context "content without block" do
5
+ not_class_self = %q{
6
+ def hello
7
+ end}
8
+
9
+ it "should not have block" do
10
+ not_class_self.should_not have_block :hello do |content|
11
+ puts content
12
+ end
13
+ end
14
+ end
15
+
16
+ context "content with block: hello do" do
17
+ content = %q{
18
+ hello do
19
+ blip
20
+ end # do}
21
+
22
+ it "should have block" do
23
+ content.should have_block :hello do |content|
24
+ puts "content: #{content}"
25
+ end
26
+ end
27
+ end
28
+
29
+ context "content with block: hello :angel do" do
30
+ content = %q{
31
+ hello :angel do
32
+ blip
33
+ end # do}
34
+
35
+ it "should have block" do
36
+ content.should have_block :hello, :args => ':angel' do |content|
37
+ puts "content: #{content}"
38
+ end
39
+ end
40
+ end
41
+
42
+ context "content with block: hello :angel do |x,y|" do
43
+ content = %q{
44
+ hello :angel do |x,y|
45
+ blip
46
+ end # do}
47
+
48
+ it "should have block" do
49
+ content.should have_block :hello, :args => ':angel', :block_args => 'x,y' do |content|
50
+ puts "content: #{content}"
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+
57
+
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'method call matcher' do
4
+ context "content without method call" do
5
+ not_call = %q{
6
+ def hello
7
+ end}
8
+
9
+ it "should not have call hello" do
10
+ not_call.should_not have_call :hello do |content|
11
+ puts content
12
+ end
13
+ end
14
+ end
15
+
16
+ context "content with call hello" do
17
+ call = 'hello'
18
+ it "should have call to hello" do
19
+ call.should have_call :hello do |content|
20
+ puts "content: #{content}"
21
+ end
22
+ end
23
+ end
24
+
25
+ context "content with call hello" do
26
+ call = %q{
27
+ def hello
28
+ x.hello
29
+ end}
30
+ it "should have call to hello" do
31
+ call.should have_dot_call :hello do |content|
32
+ puts "content: #{content}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+
39
+
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'method calls matcher' do
4
+ # context "content without calls" do
5
+ # not_class_self = %q{
6
+ # def x
7
+ # end
8
+ #
9
+ # def y
10
+ # end
11
+ # }
12
+ #
13
+ # it "should not have calls to x or y" do
14
+ # not_class_self.should_not have_calls :x, :y do |content|
15
+ # puts content
16
+ # end
17
+ # end
18
+ # end
19
+
20
+ context "content with calls to x and y" do
21
+ class_self = %q{
22
+ def x
23
+ x
24
+ y
25
+ end}
26
+
27
+ it "should have calls to x and y" do
28
+ class_self.should have_calls :x, :y do |content|
29
+ puts "content: #{content}"
30
+ end
31
+ end
32
+ end
33
+
34
+ # context "content with calls to x and y" do
35
+ # class_self = %q{
36
+ # def x
37
+ # x(2)
38
+ # y 3
39
+ # end}
40
+ #
41
+ # it "should have calls: x(2) and y 3" do
42
+ # class_self.should have_calls :x => '2', :y => '3' do |content|
43
+ # puts "content: #{content}"
44
+ # end
45
+ # end
46
+ # end
47
+ end
48
+
49
+
50
+
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'module matcher' do
4
+ context "content without class Hello" do
5
+ no_class = %q{
6
+ module Hello
7
+ def hello
8
+ end
9
+ end}
10
+
11
+ it "should not have class Hello" do
12
+ no_class.should_not have_class :Hello do |content|
13
+ puts content
14
+ end
15
+ end
16
+ end
17
+
18
+ context "content with class Hello" do
19
+ with_class = %q{
20
+ class Hello
21
+ def hello
22
+ end
23
+ end}
24
+
25
+ it "should have class Hello" do
26
+ with_class.should have_class :Hello do |content|
27
+ puts content
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'method matcher' do
4
+ context "content without method" do
5
+ no_method = %q{
6
+ class X
7
+ end}
8
+
9
+ it "should not have method hello" do
10
+ no_method.should_not have_method :hello do |content|
11
+ puts content
12
+ end
13
+ end
14
+ end
15
+
16
+ context "content with method hello" do
17
+ with_method = %q{
18
+ def hello
19
+ end}
20
+ it "should have method hello" do
21
+ with_method.should have_method :hello do |content|
22
+ puts "content: #{content}"
23
+ end
24
+ end
25
+ end
26
+
27
+ context "content: method hello with args (x, y)" do
28
+ with_method = %q{
29
+ def hello(x, y)
30
+ end}
31
+ it "should have method hello" do
32
+ with_method.should have_method :hello, :args => 'x, y' do |content|
33
+ puts "content: #{content}"
34
+ end
35
+ end
36
+ end
37
+
38
+ context "content: method hello with args x, y" do
39
+ with_method = %q{
40
+ def hello x, y
41
+ end}
42
+ it "should have method hello with args x, y" do
43
+ with_method.should have_method :hello, :args => 'x, y' do |content|
44
+ puts "content: #{content}"
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+
52
+
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'module matcher' do
4
+ context "content without module Hello" do
5
+ no_module = %q{
6
+ class Hello
7
+ def hello
8
+ end
9
+ end}
10
+
11
+ it "should not have module Hello" do
12
+ no_module.should_not have_module :Hello do |content|
13
+ puts content
14
+ end
15
+ end
16
+ end
17
+
18
+ context "content with module Hello" do
19
+ with_module = %q{
20
+ module Hello
21
+ def hello
22
+ end
23
+ end}
24
+
25
+ it "should have module Hello" do
26
+ with_module.should have_module :Hello do |content|
27
+ puts content
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'region matcher' do
4
+ context "content with only protected region" do
5
+ only_protected_region = %q{
6
+ def hello
7
+ end
8
+
9
+ protected
10
+
11
+ def goodbye
12
+ end
13
+
14
+ }
15
+
16
+ it "should not have public region" do
17
+ only_protected_region.should_not have_region :public do |content|
18
+ puts content
19
+ end
20
+ end
21
+
22
+ it "should have protected region" do
23
+ only_protected_region.should have_region :protected do |content|
24
+ puts content
25
+ end
26
+ end
27
+ end
28
+
29
+ context "content with only private region" do
30
+ only_private_region = %q{
31
+ def hello
32
+ end
33
+
34
+ private
35
+
36
+ def goodbye
37
+ end
38
+
39
+ }
40
+
41
+ it "should not have public region" do
42
+ only_private_region.should_not have_region :public do |content|
43
+ puts content
44
+ end
45
+ end
46
+
47
+ it "should have private region" do
48
+ only_private_region.should have_region :private do |content|
49
+ puts content
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+
56
+
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'subclass matcher' do
4
+ context "content without subclass Greeting" do
5
+ no_subclass = %q{
6
+ class Hello
7
+ def hello
8
+ end
9
+ end}
10
+
11
+ it "should not have subclass Greeting" do
12
+ no_subclass.should_not have_subclass :hello, :greeting do |content|
13
+ puts content
14
+ end
15
+ end
16
+ end
17
+
18
+ context "content with subclass Greeting" do
19
+ with_subclass = %q{
20
+ class Hello < Greeting
21
+ def hello
22
+ end
23
+ end}
24
+
25
+ it "should not have subclass Greeting" do
26
+ with_subclass.should have_subclass :hello, :greeting do |content|
27
+ puts content
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'include module matcher' do
4
+ context "content without include Greeting" do
5
+ no_include = %q{
6
+ class Hello < Greeting
7
+ def hello
8
+ end
9
+ end}
10
+
11
+ it "should not have include Greeting" do
12
+ no_include.should_not include_module :greeting do |content|
13
+ puts content
14
+ end
15
+ end
16
+ end
17
+
18
+ context "content with include Greeting" do
19
+ with_module = %q{
20
+ class Hello
21
+ include Greeting
22
+
23
+ def hello
24
+ end
25
+ end}
26
+
27
+ it "should have include Greeting" do
28
+ with_module.should include_module :greeting do |content|
29
+ puts content
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+
36
+
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'inherit matcher' do
4
+ context "content with class that inherits from Greeting" do
5
+ no_subclass = %q{
6
+ class Hello
7
+ def hello
8
+ end
9
+ end}
10
+
11
+ it "should not inherit from Greeting" do
12
+ no_subclass.should_not inherit_from :greeting do |content|
13
+ puts content
14
+ end
15
+ end
16
+ end
17
+
18
+ context "content with subclass Greeting" do
19
+ with_subclass = %q{
20
+ class Hello < Greeting
21
+ def hello
22
+ end
23
+ end}
24
+
25
+ it "should not inherit_from Greeting" do
26
+ with_subclass.should inherit_from :greeting do |content|
27
+ puts content
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+
File without changes
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe 'controller' do
4
+ include RSpec::Rails::Controller
5
+
6
+ before :each do
7
+ create_controller :account do
8
+ %q{
9
+ def index
10
+ end
11
+ }
12
+ end
13
+ end
14
+
15
+ after :each do
16
+ remove_controller :account
17
+ end
18
+
19
+ it "should have an account_controller file that contains an AccountController class with an index method inside" do
20
+ Rails.application.should have_controller :account do |controller_file|
21
+ controller_file.should have_controller_class :account do |klass|
22
+ klass.should have_method :index
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe 'rails helper' do
4
+ include RSpec::Rails::Helper
5
+
6
+ before :each do
7
+ create_helper :account do
8
+ %q{
9
+ def help_me
10
+ end
11
+ }
12
+ end
13
+ end
14
+
15
+ after :each do
16
+ remove_helper :account
17
+ end
18
+
19
+ it "should have an account_helper file that contains an AccountHelper class with a help_me method inside" do
20
+ Rails.application.should have_helper :account do |file|
21
+ file.should have_helper_class :account do |klass|
22
+ klass.should have_method :help_me
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe 'mailer helper' do
4
+ include RSpec::Rails::Mailer
5
+
6
+ before :each do
7
+ create_mailer :account do
8
+ %q{
9
+ def mail_it!
10
+ end
11
+ }
12
+ end
13
+ end
14
+
15
+ after :each do
16
+ remove_mailer :account
17
+ end
18
+
19
+ it "should have an account mailer file with a mail_it! method inside" do
20
+ Rails.application.should have_mailer :account do |file|
21
+ file.should have_method :mail_it!
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe 'model helper' do
4
+ include RSpec::Rails::Orm::ActiveRecord
5
+
6
+ before :each do
7
+ create_model :account
8
+ end
9
+
10
+ after :each do
11
+ remove_model :account
12
+ end
13
+
14
+ it "should have an :account model file that contains an Account class" do
15
+ Rails.application.should have_model :account do |file|
16
+ file.should have_class :account
17
+ end
18
+ end
19
+ end
20
+
21
+ describe 'model helper - no ORM helper' do
22
+ include RSpec::Rails::Model
23
+
24
+ after :each do
25
+ remove_model :account
26
+ end
27
+
28
+ it "should not be able to create a model without including an ORM helper" do
29
+ lambda {create_model :account}.should raise_error
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe 'observer helper' do
4
+ include RSpec::Rails::Observer
5
+
6
+ before :each do
7
+ create_observer :account
8
+ end
9
+
10
+ after :each do
11
+ remove_observer :account
12
+ end
13
+
14
+ it "should have an :account observer file that contains an AccountObserver class" do
15
+ Rails.application.should have_observer :account do |file|
16
+ file.should have_observer_class :account
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe 'rails view helper' do
4
+ include RSpec::Rails::View
5
+
6
+ before :each do
7
+ create_view :account, :edit do
8
+ %q{
9
+ <h1><%= title %></h1>
10
+ }
11
+ end
12
+ end
13
+
14
+ after :each do
15
+ remove_view :account, :edit
16
+ end
17
+
18
+ it "should have an account/edit view file that displays a title" do
19
+ Rails.application.should have_view :account, :edit do |file|
20
+ file.should match /<%=\s*title\s*%>/
21
+ end
22
+ end
23
+ end