rails-app-spec 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +4 -6
- data/VERSION +1 -1
- data/lib/rails_app_spec/matchers/artifact/have_artifact.rb +43 -7
- data/lib/rails_app_spec/matchers/artifact/have_artifact_file.rb +3 -2
- data/lib/rails_app_spec/matchers/file/have_rails_file.rb +33 -9
- data/rails-app-spec.gemspec +5 -4
- data/spec/rails_app_spec/matchers/artifact/helper_spec.rb +1 -1
- data/spec/rails_app_spec/matchers/artifact/mailer_spec.rb +1 -1
- data/spec/rails_app_spec/matchers/artifact/migration_spec.rb +43 -0
- data/spec/rails_app_spec/matchers/artifact/model_spec.rb +1 -1
- data/spec/rails_app_spec/matchers/artifact/observer_spec.rb +1 -1
- data/spec/rails_app_spec/matchers/artifact/view_spec.rb +17 -11
- data/spec/spec_helper.rb +1 -2
- metadata +5 -4
- data/tmp_rails/app/model/account_observer.rb +0 -3
data/README.markdown
CHANGED
@@ -4,7 +4,7 @@ RSpec 2 matchers to spec the structure of your Rails 3 app
|
|
4
4
|
|
5
5
|
## Install
|
6
6
|
|
7
|
-
<code>gem install
|
7
|
+
<code>gem install rails-app-spec</code>
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
@@ -12,6 +12,9 @@ See specs for details on the API.
|
|
12
12
|
|
13
13
|
Usage example (teaser):
|
14
14
|
<pre>
|
15
|
+
require 'rails3_assist'
|
16
|
+
require 'rails-app-spec'
|
17
|
+
|
15
18
|
Rails.root.should have_controller :account do |content|
|
16
19
|
content.should have_method :index
|
17
20
|
end
|
@@ -24,11 +27,6 @@ Usage example (teaser):
|
|
24
27
|
end
|
25
28
|
</pre>
|
26
29
|
|
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
30
|
## Note on Patches/Pull Requests
|
33
31
|
|
34
32
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -5,6 +5,10 @@ module RSpec::RailsApp::Artifact
|
|
5
5
|
class HaveArtifact < RSpec::RubyContentMatcher
|
6
6
|
|
7
7
|
include ::Rails::Assist::App
|
8
|
+
|
9
|
+
include Rails::Migration::Assist::ClassMethods
|
10
|
+
include ::Rails::Assist::BaseHelper::FileName
|
11
|
+
include ::Rails::Assist::Migration::FileName
|
8
12
|
|
9
13
|
attr_accessor :artifact_type, :artifact_name, :class_type, :content
|
10
14
|
# class
|
@@ -12,6 +16,8 @@ module RSpec::RailsApp::Artifact
|
|
12
16
|
# subclass
|
13
17
|
attr_accessor :superclass
|
14
18
|
|
19
|
+
attr_accessor :folder, :action, :view_ext
|
20
|
+
|
15
21
|
SUPERCLASS_MAP = {
|
16
22
|
:observer => 'ActiveRecord::Observer',
|
17
23
|
:mailer => 'ActionMailer::Base',
|
@@ -25,9 +31,19 @@ module RSpec::RailsApp::Artifact
|
|
25
31
|
end
|
26
32
|
|
27
33
|
def initialize(name, artifact_type)
|
28
|
-
# artifact file
|
29
34
|
self.artifact_type = artifact_type
|
35
|
+
|
36
|
+
if name.kind_of? Hash
|
37
|
+
view_options = name
|
38
|
+
self.folder = view_options[:folder]
|
39
|
+
self.action = view_options[:action]
|
40
|
+
self.view_ext = view_options[:view_ext]
|
41
|
+
self.artifact_type = :view
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
|
30
45
|
self.postfix = artifact_type.to_s.camelize if has_postfix? artifact_type
|
46
|
+
self.artifact_name = name.to_s.downcase
|
31
47
|
self.name = name.to_s.camelize
|
32
48
|
|
33
49
|
case artifact_type
|
@@ -48,13 +64,27 @@ module RSpec::RailsApp::Artifact
|
|
48
64
|
end
|
49
65
|
end
|
50
66
|
|
51
|
-
def matches?(generator, &block)
|
52
|
-
self.artifact_name =
|
67
|
+
def matches?(generator, &block)
|
68
|
+
self.artifact_name = case artifact_type
|
69
|
+
when :view
|
70
|
+
File.expand_path(send :"#{artifact_type}_file_name", folder, action, view_ext)
|
71
|
+
else
|
72
|
+
found_file = send :existing_file_name, artifact_name, artifact_type if respond_to? :existing_file_name
|
73
|
+
# send :"#{artifact_type}_file_name", artifact_name
|
74
|
+
end
|
75
|
+
|
76
|
+
self.artifact_name = File.expand_path(artifact_name)
|
77
|
+
|
53
78
|
@file_found = File.file?(artifact_name)
|
54
79
|
return nil if !@file_found
|
55
80
|
|
56
81
|
# check file content for class or subclass
|
57
|
-
self.content = File.read(artifact_name)
|
82
|
+
self.content = File.read(artifact_name)
|
83
|
+
|
84
|
+
if artifact_type == :view
|
85
|
+
yield content if block
|
86
|
+
return true
|
87
|
+
end
|
58
88
|
super content, &block
|
59
89
|
end
|
60
90
|
|
@@ -81,8 +111,8 @@ module RSpec::RailsApp::Artifact
|
|
81
111
|
"have the name: #{name}#{postfix} and be a subclass of: #{superclass}"
|
82
112
|
when :class
|
83
113
|
"have the name: #{name}#{postfix}"
|
84
|
-
else
|
85
|
-
raise "Class type must be either :class or :subclass, was #{class_type}"
|
114
|
+
else
|
115
|
+
raise "Class type must be either :class or :subclass, was #{class_type}" if artifact_type != :view
|
86
116
|
end
|
87
117
|
end
|
88
118
|
|
@@ -111,7 +141,13 @@ module RSpec::RailsApp::Artifact
|
|
111
141
|
end
|
112
142
|
alias_method :contain_#{name}, :have_#{name}
|
113
143
|
}
|
114
|
-
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def have_view folder, action=nil, view_ext=nil
|
147
|
+
arg = {:folder => folder, :action => action, :view_ext => view_ext}
|
148
|
+
have_artifact arg, :view
|
149
|
+
end
|
150
|
+
alias_method :contain_view, :have_view
|
115
151
|
end
|
116
152
|
end
|
117
153
|
|
@@ -11,8 +11,9 @@ module RSpec::RailsApp::ArtifactFile
|
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
|
-
def have_view_file
|
15
|
-
|
14
|
+
def have_view_file folder, action= :show, view_ext='html.erb'
|
15
|
+
arg = {:folder => folder, :action => action, :view_ext => view_ext}
|
16
|
+
have_rails_file arg, :view
|
16
17
|
end
|
17
18
|
alias_method :contain_view_file, :have_view_file
|
18
19
|
end
|
@@ -2,16 +2,40 @@ module RSpec::RailsApp::File
|
|
2
2
|
module Matchers
|
3
3
|
class HaveRailsFile
|
4
4
|
include ::Rails::Assist::App
|
5
|
+
|
6
|
+
include Rails::Migration::Assist::ClassMethods
|
7
|
+
include ::Rails::Assist::BaseHelper::FileName
|
8
|
+
include ::Rails::Assist::Migration::FileName
|
5
9
|
|
6
|
-
attr_accessor :name, :
|
10
|
+
attr_accessor :name, :artifact_type, :artifact_name
|
11
|
+
|
12
|
+
attr_accessor :folder, :action, :view_ext
|
7
13
|
|
8
|
-
def initialize(name,
|
9
|
-
self.
|
10
|
-
|
14
|
+
def initialize(name, artifact_type = nil)
|
15
|
+
self.artifact_type = artifact_type
|
16
|
+
|
17
|
+
if name.kind_of? Hash
|
18
|
+
view_options = name
|
19
|
+
self.folder = view_options[:folder]
|
20
|
+
self.action = view_options[:action]
|
21
|
+
self.view_ext = view_options[:view_ext]
|
22
|
+
self.artifact_type = :view
|
23
|
+
return nil
|
24
|
+
end
|
25
|
+
self.artifact_name = name.to_s
|
11
26
|
end
|
12
27
|
|
13
28
|
def matches?(generator, &block)
|
14
|
-
self.artifact_name =
|
29
|
+
self.artifact_name = case artifact_type
|
30
|
+
when :view
|
31
|
+
File.expand_path(send :"#{artifact_type}_file_name", folder, action, view_ext)
|
32
|
+
else
|
33
|
+
found_file = send :existing_file_name, artifact_name, artifact_type if respond_to? :existing_file_name
|
34
|
+
# send :"#{artifact_type}_file_name", artifact_name
|
35
|
+
end
|
36
|
+
|
37
|
+
# puts "artifact_name: #{artifact_name}"
|
38
|
+
|
15
39
|
match = File.file? artifact_name
|
16
40
|
if block && match
|
17
41
|
yield File.read(artifact_name)
|
@@ -20,17 +44,17 @@ module RSpec::RailsApp::File
|
|
20
44
|
end
|
21
45
|
|
22
46
|
def failure_message
|
23
|
-
"Expected the #{
|
47
|
+
"Expected the #{artifact_type} #{artifact_name} to exist, but it didn't"
|
24
48
|
end
|
25
49
|
|
26
50
|
def negative_failure_message
|
27
|
-
"Did not expect the #{
|
51
|
+
"Did not expect the #{artifact_type} #{artifact_name} to exist, but it did"
|
28
52
|
end
|
29
53
|
|
30
54
|
end
|
31
55
|
|
32
|
-
def have_rails_file(relative,
|
33
|
-
HaveRailsFile.new(relative,
|
56
|
+
def have_rails_file(relative, artifact_type = nil)
|
57
|
+
HaveRailsFile.new(relative, artifact_type)
|
34
58
|
end
|
35
59
|
alias_method :contain_rails_file, :have_rails_file
|
36
60
|
end
|
data/rails-app-spec.gemspec
CHANGED
@@ -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.
|
8
|
+
s.version = "0.2.0"
|
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-08-
|
12
|
+
s.date = %q{2010-08-20}
|
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 = [
|
@@ -38,13 +38,13 @@ Gem::Specification.new do |s|
|
|
38
38
|
"spec/rails_app_spec/matchers/artifact/controller_spec.rb",
|
39
39
|
"spec/rails_app_spec/matchers/artifact/helper_spec.rb",
|
40
40
|
"spec/rails_app_spec/matchers/artifact/mailer_spec.rb",
|
41
|
+
"spec/rails_app_spec/matchers/artifact/migration_spec.rb",
|
41
42
|
"spec/rails_app_spec/matchers/artifact/model_spec.rb",
|
42
43
|
"spec/rails_app_spec/matchers/artifact/observer_spec.rb",
|
43
44
|
"spec/rails_app_spec/matchers/artifact/view_spec.rb",
|
44
45
|
"spec/rails_app_spec/matchers/file/have_dir_spec.rb",
|
45
46
|
"spec/rails_app_spec/matchers/file/have_file_spec.rb",
|
46
|
-
"spec/spec_helper.rb"
|
47
|
-
"tmp_rails/app/model/account_observer.rb"
|
47
|
+
"spec/spec_helper.rb"
|
48
48
|
]
|
49
49
|
s.homepage = %q{http://github.com/kristianmandrup/rails-app-spec}
|
50
50
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -56,6 +56,7 @@ Gem::Specification.new do |s|
|
|
56
56
|
"spec/rails_app_spec/matchers/artifact/controller_spec.rb",
|
57
57
|
"spec/rails_app_spec/matchers/artifact/helper_spec.rb",
|
58
58
|
"spec/rails_app_spec/matchers/artifact/mailer_spec.rb",
|
59
|
+
"spec/rails_app_spec/matchers/artifact/migration_spec.rb",
|
59
60
|
"spec/rails_app_spec/matchers/artifact/model_spec.rb",
|
60
61
|
"spec/rails_app_spec/matchers/artifact/observer_spec.rb",
|
61
62
|
"spec/rails_app_spec/matchers/artifact/view_spec.rb",
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
Rails::Migration::Assist.orm = :active_record
|
4
|
+
|
5
|
+
describe 'migration' do
|
6
|
+
# use_orm :active_record
|
7
|
+
use_helpers :app, :migration
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
remove_migration :create_account
|
11
|
+
|
12
|
+
create_migration :create_account do
|
13
|
+
%q{ def self.up
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
end}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
after :each do
|
22
|
+
# remove_migration :create_account
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have an create_account_migration file that contains an index method and two inserted comments" do
|
26
|
+
insert_into_migration :create_account, :content => '# hello'
|
27
|
+
insert_into_migration :create_account do
|
28
|
+
'# goodbye'
|
29
|
+
end
|
30
|
+
read_migration(:create_account).should have_comment 'hello'
|
31
|
+
puts read_migration(:create_account)
|
32
|
+
|
33
|
+
puts migration_file_name :create_account
|
34
|
+
|
35
|
+
root_dir.should have_migration :create_account
|
36
|
+
|
37
|
+
# root_dir.should have_migration :create_account do |migration_file|
|
38
|
+
# migration_file.should have_method :index
|
39
|
+
# migration_file.should have_comment 'hello'
|
40
|
+
# migration_file.should have_comment 'goodbye'
|
41
|
+
# end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'rails view helper' do
|
4
4
|
use_helper :view
|
5
5
|
|
6
|
-
before
|
6
|
+
before do
|
7
7
|
create_view :account, :edit do
|
8
8
|
%q{
|
9
9
|
<h1><%= title %></h1>
|
@@ -11,17 +11,23 @@ describe 'rails view helper' do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
after
|
15
|
-
remove_view :account, :edit
|
14
|
+
after do
|
15
|
+
# remove_view :account, :edit
|
16
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
17
|
|
23
|
-
|
24
|
-
|
18
|
+
describe '#have_view' do
|
19
|
+
it "should have an account/edit view file that displays a title" do
|
20
|
+
root_dir.should have_view :account, :edit do |klass|
|
21
|
+
klass.should match /<%=\s*title\s*%>/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#have_view_file' do
|
27
|
+
it "should have an account/edit view file that displays a title" do
|
28
|
+
root_dir.should have_view_file :account, :edit do |file|
|
29
|
+
file.should match /<%=\s*title\s*%>/
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'rspec/autorun'
|
3
|
-
require 'rails3_assist'
|
4
3
|
require 'rails-app-spec'
|
5
4
|
|
6
5
|
RSpec.configure do |config|
|
@@ -9,7 +8,7 @@ RSpec.configure do |config|
|
|
9
8
|
end
|
10
9
|
|
11
10
|
config.after do
|
12
|
-
|
11
|
+
remove_temp_dir 'tmp_rails'
|
13
12
|
end
|
14
13
|
|
15
14
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.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-20 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -125,13 +125,13 @@ files:
|
|
125
125
|
- spec/rails_app_spec/matchers/artifact/controller_spec.rb
|
126
126
|
- spec/rails_app_spec/matchers/artifact/helper_spec.rb
|
127
127
|
- spec/rails_app_spec/matchers/artifact/mailer_spec.rb
|
128
|
+
- spec/rails_app_spec/matchers/artifact/migration_spec.rb
|
128
129
|
- spec/rails_app_spec/matchers/artifact/model_spec.rb
|
129
130
|
- spec/rails_app_spec/matchers/artifact/observer_spec.rb
|
130
131
|
- spec/rails_app_spec/matchers/artifact/view_spec.rb
|
131
132
|
- spec/rails_app_spec/matchers/file/have_dir_spec.rb
|
132
133
|
- spec/rails_app_spec/matchers/file/have_file_spec.rb
|
133
134
|
- spec/spec_helper.rb
|
134
|
-
- tmp_rails/app/model/account_observer.rb
|
135
135
|
has_rdoc: true
|
136
136
|
homepage: http://github.com/kristianmandrup/rails-app-spec
|
137
137
|
licenses: []
|
@@ -169,6 +169,7 @@ test_files:
|
|
169
169
|
- spec/rails_app_spec/matchers/artifact/controller_spec.rb
|
170
170
|
- spec/rails_app_spec/matchers/artifact/helper_spec.rb
|
171
171
|
- spec/rails_app_spec/matchers/artifact/mailer_spec.rb
|
172
|
+
- spec/rails_app_spec/matchers/artifact/migration_spec.rb
|
172
173
|
- spec/rails_app_spec/matchers/artifact/model_spec.rb
|
173
174
|
- spec/rails_app_spec/matchers/artifact/observer_spec.rb
|
174
175
|
- spec/rails_app_spec/matchers/artifact/view_spec.rb
|