rails-app-spec 0.2.8 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -25,6 +25,8 @@ Usage example (teaser):
25
25
  end
26
26
  end
27
27
 
28
+ Rails.root.should have_view_files :edit, :new, :show, :folder => :person
29
+
28
30
  Rails.root.should have_view_dirs :person, :post, :blog
29
31
 
30
32
  Rails.root.should have_model_dirs :admin, :editor
@@ -38,10 +40,6 @@ end
38
40
 
39
41
  This library takes advantage of *code-spec*, *file-spec* and other essential spec extensions I have created ;)
40
42
 
41
- ## TODO
42
-
43
- Finish specs for the file matchers including the special file matchers to make sure they work!
44
-
45
43
  ## Note on Patches/Pull Requests
46
44
 
47
45
  * Fork the project.
data/Rakefile CHANGED
@@ -9,9 +9,9 @@ begin
9
9
  gem.authors = ["Kristian Mandrup"]
10
10
  gem.add_dependency "rspec", "~> 2.0.0.beta.22"
11
11
  gem.add_dependency "require_all", "~> 1.1.0"
12
- gem.add_dependency "rails3_artifactor", "~> 0.1.4"
13
- gem.add_dependency "sugar-high", "~> 0.2.6"
14
- gem.add_dependency "code-spec", "~> 0.2.1"
12
+ gem.add_dependency "rails3_artifactor", "~> 0.2.4"
13
+ gem.add_dependency "sugar-high", "~> 0.2.8"
14
+ gem.add_dependency "code-spec", "~> 0.2.5"
15
15
  gem.add_dependency "file-spec", "~> 0.1.1"
16
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.2.10
@@ -16,17 +16,21 @@ module RSpec::RailsApp::Artifact
16
16
 
17
17
  def matches?(root_path, &block)
18
18
  @root_path = root_path
19
- artifact_found = find_artifact
20
- return nil if !artifact_found
19
+ begin
20
+ artifact_found = find_artifact
21
+ return nil if !artifact_found
21
22
 
22
- # check file content for class or subclass
23
- self.content = File.read(artifact_found)
23
+ # check file content for class or subclass
24
+ self.content = File.read(artifact_found)
24
25
 
25
- if artifact_type == :view
26
- yield content if block
27
- return true
26
+ if artifact_type == :view
27
+ yield content if block
28
+ return true
29
+ end
30
+ super content, &block
31
+ rescue
32
+ false
28
33
  end
29
- super content, &block
30
34
  end
31
35
  end
32
36
 
@@ -11,7 +11,6 @@ module RSpec::RailsApp::Artifact
11
11
 
12
12
  def initialize(artifact_type, *names)
13
13
  extend "Rails3::Assist::Artifact::#{artifact_type.to_s.camelize}".constantize
14
-
15
14
  @names = names
16
15
  parse_type artifact_type
17
16
  if artifact_type == :view
@@ -23,23 +22,33 @@ module RSpec::RailsApp::Artifact
23
22
 
24
23
  def matches?(root_path, &block)
25
24
  @root_path = root_path
26
-
27
- names.to_strings.each do |name|
28
- parse_name name
29
- artifact_found = find_artifact
25
+ begin
26
+ labels = names.to_strings
27
+ return false if labels.empty?
28
+ labels.each do |name|
29
+ parse_name name
30
+
31
+ @artifact_found = find_artifact
32
+ @artifact_name = name
33
+
34
+ return false if !artifact_found
35
+ return false if !File.file? artifact_found
30
36
 
31
- # check file content for class or subclass
32
- self.content = File.read(artifact_found)
37
+ # check file content for class or subclass
38
+ self.content = File.read(artifact_found)
33
39
 
34
- res = if artifact_type == :view
35
- true
36
- else
37
- super content
40
+ res = if artifact_type == :view
41
+ true
42
+ else
43
+ super content
44
+ end
45
+ return false if !res
38
46
  end
39
- return false if !res
47
+ yield if block
48
+ true
49
+ rescue
50
+ nil
40
51
  end
41
- yield if block
42
- true
43
52
  end
44
53
 
45
54
  protected
@@ -21,13 +21,16 @@ module RSpec::RailsApp::ArtifactFile
21
21
  end
22
22
 
23
23
  def matches?(root_path, &block)
24
- self.artifact_name = get_artifact_name
25
-
26
- match = File.file? artifact_name
27
- if block && match
28
- yield File.read(artifact_name)
24
+ begin
25
+ self.artifact_name = get_artifact_name
26
+ match = File.file? artifact_name
27
+ if block && match
28
+ yield File.read(artifact_name)
29
+ end
30
+ match
31
+ rescue
32
+ false
29
33
  end
30
- match
31
34
  end
32
35
  end
33
36
 
@@ -13,14 +13,20 @@ module RSpec::RailsApp::ArtifactFile
13
13
  @artifact_type = artifact_type
14
14
  end
15
15
 
16
- def matches?(root_path, &block)
17
- names.to_strings.each do |name|
18
- @artifact_name = name
19
- @artifact_name = get_artifact_name
20
- return false if !File.file?(artifact_name)
16
+ def matches?(root_path, &block)
17
+ labels = names.to_strings
18
+ return false if labels.empty?
19
+ begin
20
+ labels.each do |name|
21
+ @artifact_name = name
22
+ @artifact_name = get_artifact_name
23
+ return false if !File.file?(artifact_name)
24
+ end
25
+ yield if block
26
+ true
27
+ rescue
28
+ false
21
29
  end
22
- yield if block
23
- true
24
30
  end
25
31
  end
26
32
 
@@ -13,7 +13,6 @@ module ArtifactFile::Matcher
13
13
 
14
14
  def set_view name
15
15
  view_options = name
16
- puts "view_options: #{view_options}"
17
16
  @folder = view_options[:folder]
18
17
  @action = view_options[:action]
19
18
  @view_ext = view_options[:view_ext]
@@ -22,13 +21,10 @@ module ArtifactFile::Matcher
22
21
 
23
22
  def handle_view artifact_type, names
24
23
  if artifact_type == :view
25
- puts "handle view"
26
24
  lang_option = last_arg({:lang => 'erb.html'}, names)
27
25
  raise ArgumentException, ':folder option must be specified in the last hash argument for #have_views' if !lang_option[:folder]
28
26
  @folder = lang_option[:folder]
29
- @view_ext = get_view_ext(lang_option[:lang] || :erb)
30
-
31
- puts "folder: #{folder}, ext: #{view_ext}"
27
+ @view_ext = get_view_ext(lang_option[:lang] || :erb)
32
28
  end
33
29
  end
34
30
 
@@ -46,12 +42,7 @@ module ArtifactFile::Matcher
46
42
  def get_artifact_name
47
43
  case artifact_type
48
44
  when :view
49
- puts "args: #{folder}"
50
- puts "args: #{artifact_name}"
51
- #, #{action}"
52
45
  path = send(:view_file_name, folder, artifact_name) #, view_ext, :root_path => root_path)
53
- # puts "path: #{path}"
54
- # File.expand_path(path)
55
46
  else
56
47
  find_existing_artifact_method = "existing_#{artifact_type}_file"
57
48
  if respond_to? find_existing_artifact_method
@@ -17,10 +17,11 @@ module Artifact::Matcher
17
17
  SUPERCLASS_MAP = {
18
18
  :observer => 'ActiveRecord::Observer',
19
19
  :mailer => 'ActionMailer::Base',
20
- :migration => 'ActiveRecord::Migration'
20
+ :migration => 'ActiveRecord::Migration',
21
+ :permit => 'Permit::Base'
21
22
  }
22
23
 
23
- POSTFIX = [:helper, :observer, :controller, :mailer]
24
+ POSTFIX = [:helper, :observer, :controller, :mailer, :permit]
24
25
 
25
26
  def has_postfix? key
26
27
  POSTFIX.include? key
@@ -29,12 +30,12 @@ module Artifact::Matcher
29
30
  def parse_type artifact_type
30
31
  @artifact_type = artifact_type
31
32
  @postfix = artifact_type.to_s.camelize if has_postfix? artifact_type
32
- case artifact_type
33
+ case artifact_type
33
34
  when :helper, :controller
34
35
  # artifact class check
35
36
  @class_type = :class
36
37
  @type = :class
37
- when :observer, :migration, :mailer
38
+ when :observer, :migration, :mailer, :permit
38
39
  @class_type = :subclass
39
40
  # artifact subclass check
40
41
  @superclass = SUPERCLASS_MAP[artifact_type]
@@ -113,7 +114,7 @@ module Artifact::Matcher
113
114
  when :subclass
114
115
  "have the name: #{name}#{postfix} and be a subclass of: #{superclass}"
115
116
  when :class
116
- "have the name: #{name}#{postfix}"
117
+ "have the name: #{name}#{postfix}"
117
118
  else
118
119
  raise "Class type must be either :class or :subclass, was #{class_type}" if artifact_type != :view
119
120
  end
@@ -10,8 +10,10 @@ module RSpec::RailsApp::Directory
10
10
  @dirs = dirs
11
11
  end
12
12
 
13
- def matches?(obj, &block)
14
- dirs.to_strings.each do |dir_name|
13
+ def matches?(obj, &block)
14
+ labels = dirs.to_strings
15
+ return false if labels.empty?
16
+ labels.each do |dir_name|
15
17
  @dir_name = dir_name
16
18
  @dir = send :"#{dir_name}_dir"
17
19
  return false if !File.directory?(dir)
@@ -13,8 +13,12 @@ module RSpec::RailsApp::File
13
13
  end
14
14
 
15
15
  def matches?(obj, &block)
16
- @file = type ? send(:"#{type}_file", name) : send(:"#{name}_file")
17
- File.file? file
16
+ begin
17
+ @file = type ? send(:"#{type}_file", name) : send(:"#{name}_file")
18
+ File.file? file
19
+ rescue
20
+ false
21
+ end
18
22
  end
19
23
  end
20
24
 
@@ -15,15 +15,19 @@ module RSpec::RailsApp::File
15
15
  end
16
16
 
17
17
  def matches?(obj, &block)
18
- puts "type: #{type}"
19
- names.to_strings.each do |name|
20
- @name = name
21
- puts "name: #{name}"
22
- @file = send(:"#{type}_file", name)
23
- return false if !File.file?(file)
18
+ begin
19
+ labels = names.to_strings
20
+ return false if labels.empty?
21
+ labels.each do |name|
22
+ @name = name
23
+ @file = send(:"#{type}_file", name)
24
+ return false if !File.file?(file)
25
+ end
26
+ yield if block
27
+ true
28
+ rescue
29
+ false
24
30
  end
25
- yield if block
26
- true
27
31
  end
28
32
  end
29
33
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails-app-spec}
8
- s.version = "0.2.8"
8
+ s.version = "0.2.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-09-15}
12
+ s.date = %q{2010-09-18}
13
13
  s.description = %q{RSpec 2 matchers to spec the structure of your Rails 3 app}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -49,9 +49,8 @@ Gem::Specification.new do |s|
49
49
  "lib/rails_app_spec/rspec.rb",
50
50
  "lib/rails_app_spec/rspec/configure.rb",
51
51
  "rails-app-spec.gemspec",
52
- "sandbox/dir_logic.rb",
53
- "sandbox/file_logic.rb",
54
52
  "spec/rails_app_spec/matchers/artifact/controller_spec.rb",
53
+ "spec/rails_app_spec/matchers/artifact/core/have_artifacts_spec.rb",
55
54
  "spec/rails_app_spec/matchers/artifact/helper_spec.rb",
56
55
  "spec/rails_app_spec/matchers/artifact/mailer_spec.rb",
57
56
  "spec/rails_app_spec/matchers/artifact/migration/migration_simple_number_spec.rb",
@@ -75,6 +74,7 @@ Gem::Specification.new do |s|
75
74
  s.summary = %q{RSpec 2 matchers to spec the structure of your Rails 3 app}
76
75
  s.test_files = [
77
76
  "spec/rails_app_spec/matchers/artifact/controller_spec.rb",
77
+ "spec/rails_app_spec/matchers/artifact/core/have_artifacts_spec.rb",
78
78
  "spec/rails_app_spec/matchers/artifact/helper_spec.rb",
79
79
  "spec/rails_app_spec/matchers/artifact/mailer_spec.rb",
80
80
  "spec/rails_app_spec/matchers/artifact/migration/migration_simple_number_spec.rb",
@@ -99,24 +99,24 @@ Gem::Specification.new do |s|
99
99
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
100
100
  s.add_runtime_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
101
101
  s.add_runtime_dependency(%q<require_all>, ["~> 1.1.0"])
102
- s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.1.4"])
103
- s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.6"])
104
- s.add_runtime_dependency(%q<code-spec>, ["~> 0.2.1"])
102
+ s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.2.4"])
103
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.8"])
104
+ s.add_runtime_dependency(%q<code-spec>, ["~> 0.2.5"])
105
105
  s.add_runtime_dependency(%q<file-spec>, ["~> 0.1.1"])
106
106
  else
107
107
  s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
108
108
  s.add_dependency(%q<require_all>, ["~> 1.1.0"])
109
- s.add_dependency(%q<rails3_artifactor>, ["~> 0.1.4"])
110
- s.add_dependency(%q<sugar-high>, ["~> 0.2.6"])
111
- s.add_dependency(%q<code-spec>, ["~> 0.2.1"])
109
+ s.add_dependency(%q<rails3_artifactor>, ["~> 0.2.4"])
110
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.8"])
111
+ s.add_dependency(%q<code-spec>, ["~> 0.2.5"])
112
112
  s.add_dependency(%q<file-spec>, ["~> 0.1.1"])
113
113
  end
114
114
  else
115
115
  s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
116
116
  s.add_dependency(%q<require_all>, ["~> 1.1.0"])
117
- s.add_dependency(%q<rails3_artifactor>, ["~> 0.1.4"])
118
- s.add_dependency(%q<sugar-high>, ["~> 0.2.6"])
119
- s.add_dependency(%q<code-spec>, ["~> 0.2.1"])
117
+ s.add_dependency(%q<rails3_artifactor>, ["~> 0.2.4"])
118
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.8"])
119
+ s.add_dependency(%q<code-spec>, ["~> 0.2.5"])
120
120
  s.add_dependency(%q<file-spec>, ["~> 0.1.1"])
121
121
  end
122
122
  end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ root_dir = Rails3::Assist::Directory.rails_root
4
+
5
+ describe 'controller' do
6
+ use_helpers :controller, :app
7
+
8
+ before :each do
9
+ create_empty_tmp :controller
10
+ create_controller :account do
11
+ %q{
12
+ def index
13
+ end
14
+ }
15
+ end
16
+ end
17
+
18
+ after :each do
19
+ remove_controllers :account, :person
20
+ end
21
+
22
+ # it "should not have :controller artifact :person" do
23
+ # root_dir.should_not have_artifact :person, :controller
24
+ # end
25
+ #
26
+ # it "should have an account_controller file that contains an AccountController class with an index method inside" do
27
+ # root_dir.should have_artifact :account, :controller do |content|
28
+ # content.should have_method :index
29
+ # end
30
+ #
31
+ # create_controller :person do
32
+ # %q{
33
+ # def index
34
+ # end
35
+ # }
36
+ # end
37
+ #
38
+ # root_dir.should have_artifacts :controller, :account, :person
39
+ # root_dir.should have_artifacts :controller, [:account, :person]
40
+ # end
41
+
42
+ it "should not have :controller artifacts :account and :user" do
43
+ root_dir.should_not have_artifacts :controller, [:account, :user]
44
+ end
45
+ end
@@ -19,6 +19,7 @@ describe 'mailer helper' do
19
19
  end
20
20
 
21
21
  it "should have an account mailer file with a mail_it! method inside" do
22
+ root_dir.should_not have_mailer :user
22
23
  root_dir.should have_mailer :account do |klass|
23
24
  klass.should have_method :mail_it!
24
25
  end
@@ -4,20 +4,32 @@ root_dir = Rails3::Assist::Directory.rails_root
4
4
 
5
5
  describe 'model helper' do
6
6
  use_orm :active_record
7
+
8
+ before :each do
9
+ create_model :account do
10
+ %q{
11
+ # hello
12
+ def do_it
13
+ end
14
+ }
15
+ end
7
16
 
8
- before :each do
9
- create_model :account, :content => '# hello'
17
+ create_model :person, :content => '# hello'
10
18
  end
11
19
 
12
20
  after :each do
13
- remove_model :account
21
+ remove_models :account, :person
14
22
  end
15
23
 
16
- it "should have an :account model file that contains an Account class" do
24
+ it "should have an :account model file that contains an Account class" do
25
+ puts read_model :account
17
26
  root_dir.should have_model_file :account do |file|
18
27
  file.should have_model_class :account
28
+ file.should have_comment 'hello'
29
+ file.should have_method :do_it
19
30
  end
20
31
  root_dir.should have_model :account
32
+ root_dir.should_not have_model :user
21
33
  end
22
34
  end
23
35
 
@@ -13,4 +13,13 @@ describe 'Rails matcher: have_rails_dirs' do
13
13
  it "should have a rails dirs :locale and :controller" do
14
14
  root_dir.should have_rails_dirs :locale, :controller
15
15
  end
16
+
17
+ it "should not have rails dirs :locale and :model" do
18
+ root_dir.should_not have_rails_dirs :locale, :model
19
+ end
20
+
21
+ it "should not have rails dirs :locale and :model - bad array" do
22
+ root_dir.should_not have_rails_dirs [[:locale, :model]]
23
+ root_dir.should_not have_rails_dirs []
24
+ end
16
25
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  root_dir = Rails3::Assist::Directory.rails_root
4
4
 
5
5
  describe 'Rails matcher: have_rails_file' do
6
- use_helpers :file, :controller
6
+ use_helpers :file, :controller, :permit
7
7
 
8
8
  before :each do
9
9
  create_controller :account do
@@ -13,6 +13,18 @@ describe 'Rails matcher: have_rails_file' do
13
13
  }
14
14
  end
15
15
 
16
+ create_permit :admin do
17
+ %q{
18
+ license :blogging
19
+ }
20
+ end
21
+
22
+ create_permit :super_admin, :base => :admin do
23
+ %q{
24
+ license :user_admin
25
+ }
26
+ end
27
+
16
28
  create_javascript :effects do
17
29
  '# effects '
18
30
  end
@@ -29,6 +41,12 @@ describe 'Rails matcher: have_rails_file' do
29
41
 
30
42
  it "should have a controller :account" do
31
43
  root_dir.should have_controller_file :account
44
+ root_dir.should_not have_controller_file :user
45
+ end
46
+
47
+ it "should have a permit for :admin role" do
48
+ root_dir.should have_permit_file :admin
49
+ root_dir.should have_permit :super_admin
32
50
  end
33
51
 
34
52
  it "should have a js :effects" do
@@ -34,9 +34,14 @@ describe 'Rails matcher: have_rails_files' do
34
34
  after :each do
35
35
  # remove_controller :account
36
36
  end
37
+
38
+ it "should not have a controller :account, :user" do
39
+ root_dir.should_not have_controller_files :account, :user
40
+ end
37
41
 
38
42
  it "should have a controller :account, :person" do
39
43
  root_dir.should have_controller_files :account, :person
44
+ root_dir.should_not have_model_files :account, :user
40
45
  end
41
46
 
42
47
  it "should have a js :effects, :noise" do
@@ -49,5 +54,6 @@ describe 'Rails matcher: have_rails_files' do
49
54
 
50
55
  it "should have a view :effects, :noise" do
51
56
  root_dir.should have_view_files :edit, :new, :folder => :person
57
+ root_dir.should_not have_view_files :edit, :unknown, :folder => :person
52
58
  end
53
59
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 8
9
- version: 0.2.8
8
+ - 10
9
+ version: 0.2.10
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-09-15 00:00:00 +02:00
17
+ date: 2010-09-18 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -59,9 +59,9 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  segments:
61
61
  - 0
62
- - 1
62
+ - 2
63
63
  - 4
64
- version: 0.1.4
64
+ version: 0.2.4
65
65
  type: :runtime
66
66
  version_requirements: *id003
67
67
  - !ruby/object:Gem::Dependency
@@ -75,8 +75,8 @@ dependencies:
75
75
  segments:
76
76
  - 0
77
77
  - 2
78
- - 6
79
- version: 0.2.6
78
+ - 8
79
+ version: 0.2.8
80
80
  type: :runtime
81
81
  version_requirements: *id004
82
82
  - !ruby/object:Gem::Dependency
@@ -90,8 +90,8 @@ dependencies:
90
90
  segments:
91
91
  - 0
92
92
  - 2
93
- - 1
94
- version: 0.2.1
93
+ - 5
94
+ version: 0.2.5
95
95
  type: :runtime
96
96
  version_requirements: *id005
97
97
  - !ruby/object:Gem::Dependency
@@ -151,9 +151,8 @@ files:
151
151
  - lib/rails_app_spec/rspec.rb
152
152
  - lib/rails_app_spec/rspec/configure.rb
153
153
  - rails-app-spec.gemspec
154
- - sandbox/dir_logic.rb
155
- - sandbox/file_logic.rb
156
154
  - spec/rails_app_spec/matchers/artifact/controller_spec.rb
155
+ - spec/rails_app_spec/matchers/artifact/core/have_artifacts_spec.rb
157
156
  - spec/rails_app_spec/matchers/artifact/helper_spec.rb
158
157
  - spec/rails_app_spec/matchers/artifact/mailer_spec.rb
159
158
  - spec/rails_app_spec/matchers/artifact/migration/migration_simple_number_spec.rb
@@ -203,6 +202,7 @@ specification_version: 3
203
202
  summary: RSpec 2 matchers to spec the structure of your Rails 3 app
204
203
  test_files:
205
204
  - spec/rails_app_spec/matchers/artifact/controller_spec.rb
205
+ - spec/rails_app_spec/matchers/artifact/core/have_artifacts_spec.rb
206
206
  - spec/rails_app_spec/matchers/artifact/helper_spec.rb
207
207
  - spec/rails_app_spec/matchers/artifact/mailer_spec.rb
208
208
  - spec/rails_app_spec/matchers/artifact/migration/migration_simple_number_spec.rb
data/sandbox/dir_logic.rb DELETED
File without changes
@@ -1,61 +0,0 @@
1
- attr_accessor :relative_path
2
-
3
- def initialize(relative_path, type = nil)
4
- @relative_path = relative_rails_file(relative_path, type)
5
- end
6
-
7
- def matches?(generator, &block)
8
- file = File.expand_path(relative_path, Rails.root)
9
- file_exists = File.exists?(file)
10
- if block && file_exists
11
- read = File.read(file)
12
- ruby_content = read.extend(RSpec::RubyContent::Helpers)
13
- yield ruby_content
14
- else
15
- file_exists
16
- end
17
- end
18
-
19
-
20
- # REFACTOR
21
-
22
- def relative_rails_file path, type = nil
23
- path = path.to_s
24
- f_name = file_name(path, type)
25
- return send :"#{type}_dir" if type
26
- File.join(::Rails.root, path)
27
- end
28
-
29
- def file_name path, type
30
- return "#{path}#{postfix(type)}.rb" if !path.include? '.'
31
- path
32
- end
33
-
34
-
35
- def postfix type
36
- "_#{type}" if ![:model].include?(type)
37
- end
38
-
39
- def folder type
40
- case type
41
- when :observer
42
- 'models'
43
- else
44
- type == :controller ? type.to_s : type.to_s.pluralize
45
- end
46
- end
47
-
48
- def base_dir type
49
- case type
50
- when :model, :controller, :view, :helper, :observer, :mailer
51
- 'app'
52
- when :migration
53
- 'db'
54
- when :javascript, :stylesheet
55
- 'public'
56
- when :initializer, :locale
57
- 'config'
58
- else
59
- ''
60
- end
61
- end