generator-spec 0.4.8 → 0.5.0
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.
- data/README.markdown +6 -0
- data/VERSION +1 -1
- data/generator-spec.gemspec +4 -2
- data/lib/generator_spec/extensions/core_ext.rb +30 -0
- data/lib/generator_spec/helpers/migration_helper.rb +15 -10
- data/lib/generator_spec/main.rb +5 -3
- data/lib/generator_spec/matchers/content/content_matcher.rb +8 -4
- data/lib/generator_spec/matchers/content/have_call.rb +4 -4
- data/lib/generator_spec/matchers/content/have_comment.rb +42 -0
- data/lib/generator_spec/matchers/file/generate_file.rb +2 -4
- data/lib/generator_spec/matchers/file/have_file.rb +2 -2
- data/lib/generator_spec/matchers/migration/have_up_down.rb +2 -0
- data/lib/generator_spec/rails_helpers/base_helper.rb +171 -0
- data/lib/generator_spec/rails_helpers/rails_app.rb +9 -2
- data/lib/generator_spec/rails_helpers/rails_controller.rb +33 -25
- data/lib/generator_spec/rails_helpers/rails_helper.rb +27 -25
- data/lib/generator_spec/rails_helpers/rails_mailer.rb +29 -21
- data/lib/generator_spec/rails_helpers/rails_migration.rb +41 -26
- data/lib/generator_spec/rails_helpers/rails_model.rb +29 -19
- data/lib/generator_spec/rails_helpers/rails_observer.rb +27 -23
- data/lib/generator_spec/rails_helpers/rails_orm.rb +33 -18
- data/lib/generator_spec/rails_helpers/rails_view.rb +42 -28
- data/spec/generator_spec/matchers/content/have_call_spec.rb +16 -0
- data/spec/generator_spec/matchers/rails/controller_matcher_spec.rb +3 -2
- data/spec/generator_spec/matchers/rails/helper_matcher_spec.rb +1 -1
- data/spec/generator_spec/matchers/rails/mailer_matcher_spec.rb +1 -1
- data/spec/generator_spec/matchers/rails/model_matcher_spec.rb +4 -4
- data/spec/generator_spec/matchers/rails/observer_matcher_spec.rb +1 -1
- data/spec/generator_spec/matchers/rails/view_matcher_spec.rb +1 -1
- data/spec/generator_spec/rails_helpers/rails_controller_spec.rb +33 -0
- data/spec/generator_spec/rails_helpers/rails_helper_spec.rb +33 -0
- data/spec/generator_spec/rails_helpers/rails_mailer_spec.rb +33 -0
- data/spec/generator_spec/rails_helpers/rails_model_spec.rb +31 -0
- data/spec/generator_spec/rails_helpers/rails_observer_spec.rb +33 -0
- data/spec/generator_spec/rails_helpers/rails_view_spec.rb +31 -0
- data/spec/spec_helper.rb +1 -1
- metadata +6 -4
@@ -1,18 +1,15 @@
|
|
1
1
|
module RSpec::Rails
|
2
2
|
module View
|
3
|
-
include RSpec::Rails::
|
3
|
+
include RSpec::Rails::BaseHelper
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
file = view_file_name(name, action, type)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
FileUtils.mkdir_p File.dirname(file)
|
12
|
-
end
|
13
|
-
|
5
|
+
# CREATE
|
6
|
+
def create_view name, options = {}, &block
|
7
|
+
file = view_file_name(name, options[:action], options[:type])
|
8
|
+
dir = File.dirname(file)
|
9
|
+
FileUtils.mkdir_p dir if !File.directory?(dir)
|
10
|
+
content = options[:content]
|
14
11
|
# set content to block
|
15
|
-
content
|
12
|
+
content ||= yield if block
|
16
13
|
|
17
14
|
# abort if no content given
|
18
15
|
return if !content
|
@@ -23,29 +20,46 @@ module RSpec::Rails
|
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
23
|
+
# READ
|
24
|
+
def read_view(name, options = {}, &block)
|
25
|
+
file_name = view_file_name(name, options[:action], options[:type])
|
26
|
+
debug "reading from: #{file_name}"
|
27
|
+
content = File.new(file_name).try :read
|
28
|
+
debug "read content: #{content}"
|
29
|
+
yield content if block
|
30
|
+
content
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# UPDATE
|
35
|
+
def insert_into_view(name, options = {}, &block)
|
36
|
+
debug "insert_into_view: #{options}"
|
37
|
+
file = view_file_name(name, options[:action], options[:type])
|
38
|
+
debug "file insertion (view): #{file}"
|
39
|
+
marker = options[:before] || options[:after]
|
40
|
+
file_insertion(file, marker, options, &block) if marker
|
39
41
|
end
|
42
|
+
alias_method :update_view, :insert_into_view
|
40
43
|
|
41
|
-
|
44
|
+
# DELETE
|
45
|
+
def remove_view name, action=nil, type=nil
|
42
46
|
file = view_file_name(name, action, type)
|
43
47
|
FileUtils.rm_f(file) if File.exist?(file)
|
44
48
|
end
|
49
|
+
alias_method :delete_view, :remove_view
|
50
|
+
|
51
|
+
def get_action action
|
52
|
+
action || 'show'
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_type type
|
56
|
+
type || 'html.erb'
|
57
|
+
end
|
45
58
|
|
46
|
-
def view_file_name name, action=
|
47
|
-
File.join(view_dir, name.to_s, "#{action}.#{type}")
|
59
|
+
def view_file_name name, action=nil, type=nil
|
60
|
+
File.join(view_dir, name.to_s, "#{get_action action}.#{get_type type}")
|
48
61
|
end
|
49
|
-
|
62
|
+
|
63
|
+
aliases_for :view
|
50
64
|
end
|
51
65
|
end
|
@@ -33,6 +33,22 @@ describe 'method call matcher' do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
+
context "class User with call role_strategy" do
|
37
|
+
clazz = %q{
|
38
|
+
class User < ActiveRecord::Base
|
39
|
+
include RoleModels::Generic
|
40
|
+
role_strategy :admin_flag
|
41
|
+
|
42
|
+
roles :admin,:user
|
43
|
+
|
44
|
+
end}
|
45
|
+
|
46
|
+
it "should have call to role_strategy with args :admin_flag" do
|
47
|
+
call.should have_call :role_strategy, :args => ':admin_flag' do |content|
|
48
|
+
puts "content: #{content}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
36
52
|
end
|
37
53
|
|
38
54
|
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
2
|
|
3
3
|
describe 'controller' do
|
4
|
-
|
5
|
-
|
4
|
+
load_helper :controller
|
5
|
+
|
6
6
|
before :each do
|
7
|
+
create_empty_tmp :controller
|
7
8
|
create_controller :account do
|
8
9
|
%q{
|
9
10
|
def index
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
2
|
|
3
3
|
describe 'model helper' do
|
4
|
-
|
4
|
+
use_orm :active_record
|
5
5
|
|
6
6
|
before :each do
|
7
|
-
create_model :account
|
7
|
+
create_model :account, :content => '# hello'
|
8
8
|
end
|
9
9
|
|
10
10
|
after :each do
|
@@ -19,9 +19,9 @@ describe 'model helper' do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe 'model helper - no ORM helper' do
|
22
|
-
|
22
|
+
load_helper :model
|
23
23
|
|
24
|
-
|
24
|
+
before :each do
|
25
25
|
remove_model :account
|
26
26
|
end
|
27
27
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe 'controller' do
|
4
|
+
helpers :controller
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
remove_controller :account
|
8
|
+
create_controller :account do
|
9
|
+
%q{
|
10
|
+
def index
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
# remove_controller :account
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have an account_controller file that contains an index method and two inserted comments" do
|
21
|
+
insert_into_controller :account, :content => '# hello'
|
22
|
+
insert_into_controller :account do
|
23
|
+
'# goodbye'
|
24
|
+
end
|
25
|
+
read_controller(:account).should have_comment 'hello'
|
26
|
+
|
27
|
+
Rails.application.should have_controller :account do |controller_file|
|
28
|
+
controller_file.should have_method :index
|
29
|
+
controller_file.should have_comment 'hello'
|
30
|
+
controller_file.should have_comment 'goodbye'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe 'helper' do
|
4
|
+
helpers :helper
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
remove_helper :account
|
8
|
+
create_helper :account do
|
9
|
+
%q{
|
10
|
+
def index
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
# remove_helper :account
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have an account_helper file that contains an index method and two inserted comments" do
|
21
|
+
insert_into_helper :account, :content => '# hello'
|
22
|
+
insert_into_helper :account do
|
23
|
+
'# goodbye'
|
24
|
+
end
|
25
|
+
read_helper(:account).should have_comment 'hello'
|
26
|
+
|
27
|
+
Rails.application.should have_helper :account do |helper_file|
|
28
|
+
helper_file.should have_method :index
|
29
|
+
helper_file.should have_comment 'hello'
|
30
|
+
helper_file.should have_comment 'goodbye'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe 'mailer' do
|
4
|
+
load_helper :mailer
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
remove_mailer :account
|
8
|
+
create_mailer :account do
|
9
|
+
%q{
|
10
|
+
def index
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
# remove_mailer :account
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have an account_mailer file that contains an index method and two inserted comments" do
|
21
|
+
insert_into_mailer :account, :content => '# hello'
|
22
|
+
insert_into_mailer :account do
|
23
|
+
'# goodbye'
|
24
|
+
end
|
25
|
+
read_mailer(:account).should have_comment 'hello'
|
26
|
+
|
27
|
+
Rails.application.should have_mailer :account do |mailer_file|
|
28
|
+
mailer_file.should have_method :index
|
29
|
+
mailer_file.should have_comment 'hello'
|
30
|
+
mailer_file.should have_comment 'goodbye'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe 'model' do
|
4
|
+
use_orm :active_record
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
remove_model :account
|
8
|
+
create_model :account do
|
9
|
+
%q{ def index
|
10
|
+
end}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
after :each do
|
15
|
+
# remove_model :account
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have an account_model file that contains an index method and two inserted comments" do
|
19
|
+
insert_into_model :account, :content => '# hello'
|
20
|
+
insert_into_model :account do
|
21
|
+
'# goodbye'
|
22
|
+
end
|
23
|
+
read_model(:account).should have_comment 'hello'
|
24
|
+
|
25
|
+
Rails.application.should have_model :account do |model_file|
|
26
|
+
model_file.should have_method :index
|
27
|
+
model_file.should have_comment 'hello'
|
28
|
+
model_file.should have_comment 'goodbye'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe 'observer' do
|
4
|
+
load_helper :observer
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
remove_observer :account
|
8
|
+
create_observer :account do
|
9
|
+
%q{
|
10
|
+
def index
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
# remove_observer :account
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have an account_observer file that contains an index method and two inserted comments" do
|
21
|
+
insert_into_observer :account, :content => '# hello'
|
22
|
+
insert_into_observer :account do
|
23
|
+
'# goodbye'
|
24
|
+
end
|
25
|
+
read_observer(:account).should have_comment 'hello'
|
26
|
+
|
27
|
+
Rails.application.should have_observer :account do |observer_file|
|
28
|
+
observer_file.should have_method :index
|
29
|
+
observer_file.should have_comment 'hello'
|
30
|
+
observer_file.should have_comment 'goodbye'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe 'view' do
|
4
|
+
load_helper :view
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
remove_view :account
|
8
|
+
create_view :account do
|
9
|
+
%q{ def index
|
10
|
+
end}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
after :each do
|
15
|
+
# remove_view :account
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have an account_view file that contains an index method and two inserted comments" do
|
19
|
+
insert_into_view :account, :content => '# hello', :before => 'def'
|
20
|
+
insert_into_view :account, :before => 'def' do
|
21
|
+
'# goodbye'
|
22
|
+
end
|
23
|
+
read_view(:account).should have_comment 'hello'
|
24
|
+
|
25
|
+
Rails.application.should have_view :account do |view_file|
|
26
|
+
view_file.should have_method :index
|
27
|
+
view_file.should have_comment 'hello'
|
28
|
+
view_file.should have_comment 'goodbye'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-14 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/generator_spec/matchers/content/have_call.rb
|
141
141
|
- lib/generator_spec/matchers/content/have_calls.rb
|
142
142
|
- lib/generator_spec/matchers/content/have_class_self.rb
|
143
|
+
- lib/generator_spec/matchers/content/have_comment.rb
|
143
144
|
- lib/generator_spec/matchers/content/have_method.rb
|
144
145
|
- lib/generator_spec/matchers/content/have_module.rb
|
145
146
|
- lib/generator_spec/matchers/content/have_region.rb
|
@@ -158,6 +159,7 @@ files:
|
|
158
159
|
- lib/generator_spec/matchers/migration/have_table.rb
|
159
160
|
- lib/generator_spec/matchers/migration/have_tbl_column.rb
|
160
161
|
- lib/generator_spec/matchers/migration/have_up_down.rb
|
162
|
+
- lib/generator_spec/rails_helpers/base_helper.rb
|
161
163
|
- lib/generator_spec/rails_helpers/rails_app.rb
|
162
164
|
- lib/generator_spec/rails_helpers/rails_controller.rb
|
163
165
|
- lib/generator_spec/rails_helpers/rails_helper.rb
|