rails-app-spec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/LICENSE +20 -0
- data/README.markdown +44 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/rails-app-spec.rb +34 -0
- data/lib/rails_app_spec/matchers/artifact/class/have_artifact_class.rb +38 -0
- data/lib/rails_app_spec/matchers/artifact/class/have_artifact_subclass.rb +34 -0
- data/lib/rails_app_spec/matchers/artifact/have_artifact.rb +117 -0
- data/lib/rails_app_spec/matchers/artifact/have_artifact_file.rb +21 -0
- data/lib/rails_app_spec/matchers/file/have_rails_dir.rb +46 -0
- data/lib/rails_app_spec/matchers/file/have_rails_file.rb +38 -0
- data/rails-app-spec.gemspec +92 -0
- data/sandbox/dir_logic.rb +0 -0
- data/sandbox/file_logic.rb +61 -0
- data/spec/load_spec.rb +4 -0
- data/spec/rails_app_spec/matchers/artifact/controller_spec.rb +31 -0
- data/spec/rails_app_spec/matchers/artifact/helper_spec.rb +30 -0
- data/spec/rails_app_spec/matchers/artifact/mailer_spec.rb +30 -0
- data/spec/rails_app_spec/matchers/artifact/model_spec.rb +32 -0
- data/spec/rails_app_spec/matchers/artifact/observer_spec.rb +20 -0
- data/spec/rails_app_spec/matchers/artifact/view_spec.rb +27 -0
- data/spec/rails_app_spec/matchers/file/have_dir_spec.rb +0 -0
- data/spec/rails_app_spec/matchers/file/have_file_spec.rb +0 -0
- data/spec/spec_helper.rb +32 -0
- data/tmp_rails/app/model/account_observer.rb +3 -0
- metadata +177 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format nested --color
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Kristian Mandrup
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Rails app RSpec 2 matchers
|
2
|
+
|
3
|
+
RSpec 2 matchers to spec the structure of your Rails 3 app
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
<code>gem install rails3-app-spec</code>
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
See specs for details on the API.
|
12
|
+
|
13
|
+
Usage example (teaser):
|
14
|
+
<pre>
|
15
|
+
Rails.root.should have_controller :account do |content|
|
16
|
+
content.should have_method :index
|
17
|
+
end
|
18
|
+
|
19
|
+
Rails.root.should have_controller_file :account do |controller_file|
|
20
|
+
controller_file.should have_controller_class :account do |klass|
|
21
|
+
klass.should have_method :index
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
</pre>
|
26
|
+
|
27
|
+
## Known issues
|
28
|
+
|
29
|
+
* View generation fails when action arg supplied :( To be fixed ASAP
|
30
|
+
- rails3_assist/artifact/view.rb:7:in `[]' can't convert Symbol into Integer
|
31
|
+
|
32
|
+
## Note on Patches/Pull Requests
|
33
|
+
|
34
|
+
* Fork the project.
|
35
|
+
* Make your feature addition or bug fix.
|
36
|
+
* Add tests for it. This is important so I don't break it in a
|
37
|
+
future version unintentionally.
|
38
|
+
* Commit, do not mess with rakefile, version, or history.
|
39
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
40
|
+
* Send me a pull request. Bonus points for topic branches.
|
41
|
+
|
42
|
+
## Copyright
|
43
|
+
|
44
|
+
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "rails-app-spec"
|
5
|
+
gem.summary = %Q{RSpec 2 matchers to spec the structure of your Rails 3 app}
|
6
|
+
gem.description = %Q{RSpec 2 matchers to spec the structure of your Rails 3 app}
|
7
|
+
gem.email = "kmandrup@gmail.com"
|
8
|
+
gem.homepage = "http://github.com/kristianmandrup/rails-app-spec"
|
9
|
+
gem.authors = ["Kristian Mandrup"]
|
10
|
+
gem.add_dependency "rspec", ">= 2.0.0.beta.19"
|
11
|
+
gem.add_dependency "require_all", ">= 1.1.0"
|
12
|
+
gem.add_dependency "rails3_assist", ">= 0.2.2"
|
13
|
+
gem.add_dependency "code-spec", ">= 0.2.1"
|
14
|
+
gem.add_dependency "file-spec", ">= 0.1.1"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
# require 'spec/rake/spectask'
|
23
|
+
# Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
# spec.libs << 'lib' << 'spec'
|
25
|
+
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
# spec.libs << 'lib' << 'spec'
|
30
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
# spec.rcov = true
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# task :spec => :check_dependencies
|
35
|
+
#
|
36
|
+
# task :default => :spec
|
37
|
+
#
|
38
|
+
# require 'rake/rdoctask'
|
39
|
+
# Rake::RDocTask.new do |rdoc|
|
40
|
+
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
#
|
42
|
+
# rdoc.rdoc_dir = 'rdoc'
|
43
|
+
# rdoc.title = "rails-app-spec #{version}"
|
44
|
+
# rdoc.rdoc_files.include('README*')
|
45
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
# end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rails3_assist'
|
3
|
+
require 'require_all'
|
4
|
+
require 'code-spec'
|
5
|
+
require 'file-spec'
|
6
|
+
|
7
|
+
module RSpec
|
8
|
+
module RailsApp
|
9
|
+
module Artifact
|
10
|
+
end
|
11
|
+
|
12
|
+
module ArtifactClass
|
13
|
+
end
|
14
|
+
|
15
|
+
module ArtifactFile
|
16
|
+
end
|
17
|
+
|
18
|
+
module File
|
19
|
+
end
|
20
|
+
|
21
|
+
module Dir
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require_all File.dirname(__FILE__) + '/rails_app_spec/matchers'
|
27
|
+
|
28
|
+
RSpec.configure do |config|
|
29
|
+
config.include RSpec::RailsApp::File::Matchers
|
30
|
+
config.include RSpec::RailsApp::Dir::Matchers
|
31
|
+
config.include RSpec::RailsApp::Artifact::Matchers
|
32
|
+
config.include RSpec::RailsApp::ArtifactClass::Matchers
|
33
|
+
config.include RSpec::RailsApp::ArtifactFile::Matchers
|
34
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RSpec::RailsApp::ArtifactClass
|
2
|
+
module Matchers
|
3
|
+
class HaveArtifactClass < RSpec::RubyContentMatchers::HaveClass
|
4
|
+
def failure_message
|
5
|
+
super
|
6
|
+
puts "Content: #{content}"
|
7
|
+
"Expected the code to have a #{postfix} class called #{name}#{postfix}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def negative_failure_message
|
11
|
+
super
|
12
|
+
puts "Content: #{content}"
|
13
|
+
"Did not expected there to be the #{postfix} class #{name}#{postfix}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def have_artifact_class(klass, type=nil)
|
18
|
+
HaveArtifactClass.new klass, type
|
19
|
+
end
|
20
|
+
|
21
|
+
def have_helper_class(klass)
|
22
|
+
have_artifact_class klass, :helper
|
23
|
+
end
|
24
|
+
alias_method :be_helper_class, :have_helper_class
|
25
|
+
|
26
|
+
|
27
|
+
def have_controller_class(klass)
|
28
|
+
have_artifact_class klass, :controller
|
29
|
+
end
|
30
|
+
alias_method :be_controller_class, :have_controller_class
|
31
|
+
|
32
|
+
def have_model_class(klass)
|
33
|
+
have_artifact_class klass
|
34
|
+
end
|
35
|
+
alias_method :be_controller_class, :have_controller_class
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RSpec::RailsApp::ArtifactClass
|
2
|
+
module Matchers
|
3
|
+
class HaveArtifactSubclass < RSpec::RubyContentMatchers::HaveSubclass
|
4
|
+
def failure_message
|
5
|
+
super
|
6
|
+
"Expected the code to have a #{postfix} subclass called #{name}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def negative_failure_message
|
10
|
+
super
|
11
|
+
"Did not expect he code to have a #{type} subclass called #{name}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def have_artifact_subclass klass, superclass, type=nil
|
16
|
+
HaveArtifactSubclass.new klass, superclass, type
|
17
|
+
end
|
18
|
+
|
19
|
+
def have_observer_class klass
|
20
|
+
have_artifact_subclass klass, 'ActiveRecord::Observer', :observer
|
21
|
+
end
|
22
|
+
# alias_method :be_observer_class, :have_observer_class
|
23
|
+
|
24
|
+
def have_mailer_class klass
|
25
|
+
have_artifact_subclass klass, 'ActionMailer::Base'
|
26
|
+
end
|
27
|
+
# alias_method :be_mailer_class, :have_mailer_class
|
28
|
+
|
29
|
+
def have_migration_class klass
|
30
|
+
have_artifact_subclass klass, 'ActiveRecord::Migration'
|
31
|
+
end
|
32
|
+
# alias_method :be_migration_class, :have_migration_class
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# Combines artifact file exist check with class check!
|
2
|
+
|
3
|
+
module RSpec::RailsApp::Artifact
|
4
|
+
module Matchers
|
5
|
+
class HaveArtifact < RSpec::RubyContentMatcher
|
6
|
+
|
7
|
+
include ::Rails::Assist::App
|
8
|
+
|
9
|
+
attr_accessor :artifact_type, :artifact_name, :class_type, :content
|
10
|
+
# class
|
11
|
+
attr_accessor :name, :type, :postfix
|
12
|
+
# subclass
|
13
|
+
attr_accessor :superclass
|
14
|
+
|
15
|
+
SUPERCLASS_MAP = {
|
16
|
+
:observer => 'ActiveRecord::Observer',
|
17
|
+
:mailer => 'ActionMailer::Base',
|
18
|
+
:migration => 'ActiveRecord::Migration'
|
19
|
+
}
|
20
|
+
|
21
|
+
POSTFIX = [:helper, :observer, :controller]
|
22
|
+
|
23
|
+
def has_postfix? key
|
24
|
+
POSTFIX.include? key
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(name, artifact_type)
|
28
|
+
# artifact file
|
29
|
+
self.artifact_type = artifact_type
|
30
|
+
self.postfix = artifact_type.to_s.camelize if has_postfix? artifact_type
|
31
|
+
self.name = name.to_s.camelize
|
32
|
+
|
33
|
+
case artifact_type
|
34
|
+
when :helper, :controller
|
35
|
+
# artifact class check
|
36
|
+
self.class_type = :class
|
37
|
+
self.type = :class
|
38
|
+
super name
|
39
|
+
when :observer, :migration, :mailer
|
40
|
+
self.class_type = :subclass
|
41
|
+
# artifact subclass check
|
42
|
+
self.superclass = SUPERCLASS_MAP[artifact_type]
|
43
|
+
super name
|
44
|
+
when :model
|
45
|
+
# check class == name
|
46
|
+
self.class_type = :class
|
47
|
+
super name
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def matches?(generator, &block)
|
52
|
+
self.artifact_name = File.expand_path(send :"#{artifact_type}_file_name", name.downcase)
|
53
|
+
@file_found = File.file?(artifact_name)
|
54
|
+
return nil if !@file_found
|
55
|
+
|
56
|
+
# check file content for class or subclass
|
57
|
+
self.content = File.read(artifact_name)
|
58
|
+
super content, &block
|
59
|
+
end
|
60
|
+
|
61
|
+
# TODO: Refactor, make DRY
|
62
|
+
def main_expr
|
63
|
+
# determine which regexp to use: class or subclass
|
64
|
+
case class_type
|
65
|
+
when :subclass
|
66
|
+
'class' + SPACES + "#{name}#{postfix}" + OPT_SPACES + '<' + OPT_SPACES + "#{superclass}" + ANY_GROUP
|
67
|
+
when :class
|
68
|
+
"#{type}" + SPACES + "#{name}#{postfix}" + SPACES + ANY_GROUP
|
69
|
+
else
|
70
|
+
raise "Class type must be either :class or :subclass, was #{class_type}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def alt_end
|
75
|
+
'class'
|
76
|
+
end
|
77
|
+
|
78
|
+
def should_be_msg
|
79
|
+
case class_type
|
80
|
+
when :subclass
|
81
|
+
"have the name: #{name}#{postfix} and be a subclass of: #{superclass}"
|
82
|
+
when :class
|
83
|
+
"have the name: #{name}#{postfix}"
|
84
|
+
else
|
85
|
+
raise "Class type must be either :class or :subclass, was #{class_type}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def failure_message
|
90
|
+
return "Expected the #{type} #{artifact_name} to exist, but it didn't" if !@file_found
|
91
|
+
puts "Content: #{content}"
|
92
|
+
"Expected the file: #{artifact_name} to have a #{artifact_type} class. The class should #{should_be_msg}"
|
93
|
+
end
|
94
|
+
|
95
|
+
def negative_failure_message
|
96
|
+
return "Did not expect the #{type} #{artifact_name} to exist, but it did" if !@file_found
|
97
|
+
puts "Content: #{content}"
|
98
|
+
"Did not expected the file: #{artifact_name} to have a #{artifact_type} class. The class should not #{should_be_msg}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def have_artifact(relative, type = nil)
|
103
|
+
HaveArtifact.new(relative, type)
|
104
|
+
end
|
105
|
+
alias_method :contain_artifact, :have_artifact
|
106
|
+
|
107
|
+
(::Rails::Assist.artifacts - [:view]).each do |name|
|
108
|
+
class_eval %{
|
109
|
+
def have_#{name} relative
|
110
|
+
have_artifact relative, :#{name}
|
111
|
+
end
|
112
|
+
alias_method :contain_#{name}, :have_#{name}
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RSpec::RailsApp::ArtifactFile
|
2
|
+
module Matchers
|
3
|
+
include ::Rails::Assist::App
|
4
|
+
|
5
|
+
(::Rails::Assist.artifacts - [:view]).each do |name|
|
6
|
+
class_eval %{
|
7
|
+
def have_#{name}_file relative
|
8
|
+
have_rails_file relative, :#{name}
|
9
|
+
end
|
10
|
+
alias_method :contain_#{name}_file, :have_#{name}_file
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def have_view_file(relative, action='show', ext='html.erb')
|
15
|
+
have_rails_file "#{relative}/#{action}.#{ext}", :view
|
16
|
+
end
|
17
|
+
alias_method :contain_view_file, :have_view_file
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RSpec::RailsApp::Dir
|
2
|
+
module Matchers
|
3
|
+
class HaveRailsDir
|
4
|
+
include ::Rails::Assist::App
|
5
|
+
|
6
|
+
attr_accessor :dir, :type
|
7
|
+
|
8
|
+
def initialize(type = nil)
|
9
|
+
@type = type
|
10
|
+
end
|
11
|
+
|
12
|
+
def matches?(obj, &block)
|
13
|
+
@dir = send :"#{type}_dir"
|
14
|
+
File.directory? dir
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message
|
18
|
+
"Expected Rails app to have dir: #{relative_path}, but it didn't"
|
19
|
+
end
|
20
|
+
|
21
|
+
def negative_failure_message
|
22
|
+
"Did not expected Rails app to have dir: #{relative_path}, but it did"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def have_rails_dir(type = nil)
|
27
|
+
HaveRailsDir.new(type)
|
28
|
+
end
|
29
|
+
|
30
|
+
::Rails::Assist::App::RailsDirs.root_directories.each do |name|
|
31
|
+
class_eval %{
|
32
|
+
def have_#{name}_dir
|
33
|
+
have_rails_dir :#{name}
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
::Rails::Assist::App::RailsDirs.app_directories.each do |name|
|
39
|
+
class_eval %{
|
40
|
+
def have_#{name}_dir
|
41
|
+
have_rails_dir :#{name}
|
42
|
+
end
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RSpec::RailsApp::File
|
2
|
+
module Matchers
|
3
|
+
class HaveRailsFile
|
4
|
+
include ::Rails::Assist::App
|
5
|
+
|
6
|
+
attr_accessor :name, :type, :artifact_name
|
7
|
+
|
8
|
+
def initialize(name, type = nil)
|
9
|
+
self.name = name
|
10
|
+
self.type = type
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches?(generator, &block)
|
14
|
+
self.artifact_name = send :"#{type}_file_name", name
|
15
|
+
match = File.file? artifact_name
|
16
|
+
if block && match
|
17
|
+
yield File.read(artifact_name)
|
18
|
+
end
|
19
|
+
match
|
20
|
+
end
|
21
|
+
|
22
|
+
def failure_message
|
23
|
+
"Expected the #{type} #{artifact_name} to exist, but it didn't"
|
24
|
+
end
|
25
|
+
|
26
|
+
def negative_failure_message
|
27
|
+
"Did not expect the #{type} #{artifact_name} to exist, but it did"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def have_rails_file(relative, type = nil)
|
33
|
+
HaveRailsFile.new(relative, type)
|
34
|
+
end
|
35
|
+
alias_method :contain_rails_file, :have_rails_file
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rails-app-spec}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = %q{2010-08-19}
|
13
|
+
s.description = %q{RSpec 2 matchers to spec the structure of your Rails 3 app}
|
14
|
+
s.email = %q{kmandrup@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
".rspec",
|
23
|
+
"LICENSE",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/rails-app-spec.rb",
|
28
|
+
"lib/rails_app_spec/matchers/artifact/class/have_artifact_class.rb",
|
29
|
+
"lib/rails_app_spec/matchers/artifact/class/have_artifact_subclass.rb",
|
30
|
+
"lib/rails_app_spec/matchers/artifact/have_artifact.rb",
|
31
|
+
"lib/rails_app_spec/matchers/artifact/have_artifact_file.rb",
|
32
|
+
"lib/rails_app_spec/matchers/file/have_rails_dir.rb",
|
33
|
+
"lib/rails_app_spec/matchers/file/have_rails_file.rb",
|
34
|
+
"rails-app-spec.gemspec",
|
35
|
+
"sandbox/dir_logic.rb",
|
36
|
+
"sandbox/file_logic.rb",
|
37
|
+
"spec/load_spec.rb",
|
38
|
+
"spec/rails_app_spec/matchers/artifact/controller_spec.rb",
|
39
|
+
"spec/rails_app_spec/matchers/artifact/helper_spec.rb",
|
40
|
+
"spec/rails_app_spec/matchers/artifact/mailer_spec.rb",
|
41
|
+
"spec/rails_app_spec/matchers/artifact/model_spec.rb",
|
42
|
+
"spec/rails_app_spec/matchers/artifact/observer_spec.rb",
|
43
|
+
"spec/rails_app_spec/matchers/artifact/view_spec.rb",
|
44
|
+
"spec/rails_app_spec/matchers/file/have_dir_spec.rb",
|
45
|
+
"spec/rails_app_spec/matchers/file/have_file_spec.rb",
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"tmp_rails/app/model/account_observer.rb"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/kristianmandrup/rails-app-spec}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.3.7}
|
53
|
+
s.summary = %q{RSpec 2 matchers to spec the structure of your Rails 3 app}
|
54
|
+
s.test_files = [
|
55
|
+
"spec/load_spec.rb",
|
56
|
+
"spec/rails_app_spec/matchers/artifact/controller_spec.rb",
|
57
|
+
"spec/rails_app_spec/matchers/artifact/helper_spec.rb",
|
58
|
+
"spec/rails_app_spec/matchers/artifact/mailer_spec.rb",
|
59
|
+
"spec/rails_app_spec/matchers/artifact/model_spec.rb",
|
60
|
+
"spec/rails_app_spec/matchers/artifact/observer_spec.rb",
|
61
|
+
"spec/rails_app_spec/matchers/artifact/view_spec.rb",
|
62
|
+
"spec/rails_app_spec/matchers/file/have_dir_spec.rb",
|
63
|
+
"spec/rails_app_spec/matchers/file/have_file_spec.rb",
|
64
|
+
"spec/spec_helper.rb"
|
65
|
+
]
|
66
|
+
|
67
|
+
if s.respond_to? :specification_version then
|
68
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
69
|
+
s.specification_version = 3
|
70
|
+
|
71
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
72
|
+
s.add_runtime_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
73
|
+
s.add_runtime_dependency(%q<require_all>, [">= 1.1.0"])
|
74
|
+
s.add_runtime_dependency(%q<rails3_assist>, [">= 0.2.2"])
|
75
|
+
s.add_runtime_dependency(%q<code-spec>, [">= 0.2.1"])
|
76
|
+
s.add_runtime_dependency(%q<file-spec>, [">= 0.1.1"])
|
77
|
+
else
|
78
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
79
|
+
s.add_dependency(%q<require_all>, [">= 1.1.0"])
|
80
|
+
s.add_dependency(%q<rails3_assist>, [">= 0.2.2"])
|
81
|
+
s.add_dependency(%q<code-spec>, [">= 0.2.1"])
|
82
|
+
s.add_dependency(%q<file-spec>, [">= 0.1.1"])
|
83
|
+
end
|
84
|
+
else
|
85
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
86
|
+
s.add_dependency(%q<require_all>, [">= 1.1.0"])
|
87
|
+
s.add_dependency(%q<rails3_assist>, [">= 0.2.2"])
|
88
|
+
s.add_dependency(%q<code-spec>, [">= 0.2.1"])
|
89
|
+
s.add_dependency(%q<file-spec>, [">= 0.1.1"])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
File without changes
|
@@ -0,0 +1,61 @@
|
|
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
|
data/spec/load_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'controller' do
|
4
|
+
use_helpers :app, :controller
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
create_empty_tmp :controller
|
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 AccountController class with an index method inside" do
|
21
|
+
root_dir.should have_controller :account do |content|
|
22
|
+
content.should have_method :index
|
23
|
+
end
|
24
|
+
|
25
|
+
root_dir.should have_controller_file :account do |controller_file|
|
26
|
+
controller_file.should have_controller_class :account do |klass|
|
27
|
+
klass.should have_method :index
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
describe 'rails helper' do
|
4
|
+
use_helper :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
|
+
root_dir.should have_helper_file :account do |file|
|
21
|
+
file.should have_helper_class :account do |klass|
|
22
|
+
klass.should have_method :help_me
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
root_dir.should have_helper :account do |klass|
|
27
|
+
klass.should have_method :help_me
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
describe 'mailer helper' do
|
4
|
+
load_helper :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
|
+
root_dir.should have_mailer :account do |klass|
|
21
|
+
klass.should have_method :mail_it!
|
22
|
+
end
|
23
|
+
|
24
|
+
root_dir.should have_mailer_file :account do |file|
|
25
|
+
file.should have_mailer_class :account do |klass|
|
26
|
+
klass.should have_method :mail_it!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
describe 'model helper' do
|
4
|
+
use_orm :active_record
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
create_model :account, :content => '# hello'
|
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
|
+
root_dir.should have_model_file :account do |file|
|
16
|
+
file.should have_model_class :account
|
17
|
+
end
|
18
|
+
root_dir.should have_model :account
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'model helper - no ORM helper' do
|
23
|
+
use_helper :model
|
24
|
+
|
25
|
+
before :each do
|
26
|
+
remove_model :account
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not be able to create a model without including an ORM helper" do
|
30
|
+
lambda {create_model :account}.should raise_error
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
describe 'observer helper' do
|
4
|
+
use_helper :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
|
+
# root_dir.should have_observer_file :account do |file|
|
16
|
+
# file.should have_observer_class :account
|
17
|
+
# end
|
18
|
+
root_dir.should have_observer :account
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
describe 'rails view helper' do
|
4
|
+
use_helper :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
|
+
root_dir.should have_view_file :account, :edit do |file|
|
20
|
+
file.should match /<%=\s*title\s*%>/
|
21
|
+
end
|
22
|
+
|
23
|
+
root_dir.should have_view :account, :edit do |klass|
|
24
|
+
file.should match /<%=\s*title\s*%>/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rspec/autorun'
|
3
|
+
require 'rails3_assist'
|
4
|
+
require 'rails-app-spec'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.before do
|
8
|
+
Rails::Assist::App.rails_root_dir = temp_dir('tmp_rails')
|
9
|
+
end
|
10
|
+
|
11
|
+
config.after do
|
12
|
+
# remove_temp_dir 'tmp_rails'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def project_dir
|
18
|
+
File.dirname(__FILE__) + '/..'
|
19
|
+
end
|
20
|
+
|
21
|
+
def temp_dir name
|
22
|
+
File.join(project_dir, name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def make_temp_dir name
|
26
|
+
FileUtils.mkdir_p temp_dir(name)
|
27
|
+
temp_dir(name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def remove_temp_dir name
|
31
|
+
FileUtils.rm_rf temp_dir(name)
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-app-spec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kristian Mandrup
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-19 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- beta
|
33
|
+
- 19
|
34
|
+
version: 2.0.0.beta.19
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: require_all
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 1
|
48
|
+
- 0
|
49
|
+
version: 1.1.0
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: rails3_assist
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 2
|
63
|
+
- 2
|
64
|
+
version: 0.2.2
|
65
|
+
type: :runtime
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: code-spec
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
- 2
|
78
|
+
- 1
|
79
|
+
version: 0.2.1
|
80
|
+
type: :runtime
|
81
|
+
version_requirements: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: file-spec
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
- 1
|
93
|
+
- 1
|
94
|
+
version: 0.1.1
|
95
|
+
type: :runtime
|
96
|
+
version_requirements: *id005
|
97
|
+
description: RSpec 2 matchers to spec the structure of your Rails 3 app
|
98
|
+
email: kmandrup@gmail.com
|
99
|
+
executables: []
|
100
|
+
|
101
|
+
extensions: []
|
102
|
+
|
103
|
+
extra_rdoc_files:
|
104
|
+
- LICENSE
|
105
|
+
- README.markdown
|
106
|
+
files:
|
107
|
+
- .document
|
108
|
+
- .gitignore
|
109
|
+
- .rspec
|
110
|
+
- LICENSE
|
111
|
+
- README.markdown
|
112
|
+
- Rakefile
|
113
|
+
- VERSION
|
114
|
+
- lib/rails-app-spec.rb
|
115
|
+
- lib/rails_app_spec/matchers/artifact/class/have_artifact_class.rb
|
116
|
+
- lib/rails_app_spec/matchers/artifact/class/have_artifact_subclass.rb
|
117
|
+
- lib/rails_app_spec/matchers/artifact/have_artifact.rb
|
118
|
+
- lib/rails_app_spec/matchers/artifact/have_artifact_file.rb
|
119
|
+
- lib/rails_app_spec/matchers/file/have_rails_dir.rb
|
120
|
+
- lib/rails_app_spec/matchers/file/have_rails_file.rb
|
121
|
+
- rails-app-spec.gemspec
|
122
|
+
- sandbox/dir_logic.rb
|
123
|
+
- sandbox/file_logic.rb
|
124
|
+
- spec/load_spec.rb
|
125
|
+
- spec/rails_app_spec/matchers/artifact/controller_spec.rb
|
126
|
+
- spec/rails_app_spec/matchers/artifact/helper_spec.rb
|
127
|
+
- spec/rails_app_spec/matchers/artifact/mailer_spec.rb
|
128
|
+
- spec/rails_app_spec/matchers/artifact/model_spec.rb
|
129
|
+
- spec/rails_app_spec/matchers/artifact/observer_spec.rb
|
130
|
+
- spec/rails_app_spec/matchers/artifact/view_spec.rb
|
131
|
+
- spec/rails_app_spec/matchers/file/have_dir_spec.rb
|
132
|
+
- spec/rails_app_spec/matchers/file/have_file_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- tmp_rails/app/model/account_observer.rb
|
135
|
+
has_rdoc: true
|
136
|
+
homepage: http://github.com/kristianmandrup/rails-app-spec
|
137
|
+
licenses: []
|
138
|
+
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options:
|
141
|
+
- --charset=UTF-8
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
segments:
|
150
|
+
- 0
|
151
|
+
version: "0"
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
segments:
|
158
|
+
- 0
|
159
|
+
version: "0"
|
160
|
+
requirements: []
|
161
|
+
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 1.3.7
|
164
|
+
signing_key:
|
165
|
+
specification_version: 3
|
166
|
+
summary: RSpec 2 matchers to spec the structure of your Rails 3 app
|
167
|
+
test_files:
|
168
|
+
- spec/load_spec.rb
|
169
|
+
- spec/rails_app_spec/matchers/artifact/controller_spec.rb
|
170
|
+
- spec/rails_app_spec/matchers/artifact/helper_spec.rb
|
171
|
+
- spec/rails_app_spec/matchers/artifact/mailer_spec.rb
|
172
|
+
- spec/rails_app_spec/matchers/artifact/model_spec.rb
|
173
|
+
- spec/rails_app_spec/matchers/artifact/observer_spec.rb
|
174
|
+
- spec/rails_app_spec/matchers/artifact/view_spec.rb
|
175
|
+
- spec/rails_app_spec/matchers/file/have_dir_spec.rb
|
176
|
+
- spec/rails_app_spec/matchers/file/have_file_spec.rb
|
177
|
+
- spec/spec_helper.rb
|