rails-app-spec 0.2.5 → 0.2.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 (31) hide show
  1. data/README.markdown +13 -0
  2. data/Rakefile +2 -1
  3. data/VERSION +1 -1
  4. data/lib/rails-app-spec.rb +2 -0
  5. data/lib/rails_app_spec/matchers/artifact/have_artifact.rb +8 -127
  6. data/lib/rails_app_spec/matchers/artifact/have_artifacts.rb +78 -0
  7. data/lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb +5 -33
  8. data/lib/rails_app_spec/matchers/artifact/have_rails_artifact_files.rb +33 -0
  9. data/lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb +56 -0
  10. data/lib/rails_app_spec/matchers/artifact/shared/artifact_helper.rb +134 -0
  11. data/lib/rails_app_spec/matchers/artifact.rb +1 -0
  12. data/lib/rails_app_spec/matchers/directory/have_artifact_dirs.rb +43 -0
  13. data/lib/rails_app_spec/matchers/{file → directory}/have_rails_dir.rb +1 -1
  14. data/lib/rails_app_spec/matchers/directory/have_rails_dirs.rb +34 -0
  15. data/lib/rails_app_spec/matchers/file/have_rails_file.rb +4 -11
  16. data/lib/rails_app_spec/matchers/file/have_rails_files.rb +39 -0
  17. data/lib/rails_app_spec/matchers/file/rails_file_helper.rb +19 -0
  18. data/lib/rails_app_spec/matchers/special/have_gem.rb +65 -0
  19. data/lib/rails_app_spec/matchers/special/have_gems.rb +56 -0
  20. data/lib/rails_app_spec/matchers.rb +1 -0
  21. data/lib/rails_app_spec/rspec/configure.rb +1 -1
  22. data/lib/rails_app_spec/rspec.rb +1 -1
  23. data/rails-app-spec.gemspec +35 -10
  24. data/spec/rails_app_spec/matchers/{file/have_dir_spec.rb → directory/have_rails_dir_spec.rb} +0 -0
  25. data/spec/rails_app_spec/matchers/{file/have_file_spec.rb → directory/have_rails_dirs_spec.rb} +0 -0
  26. data/spec/rails_app_spec/matchers/file/have_rails_file_spec.rb +0 -0
  27. data/spec/rails_app_spec/matchers/file/have_rails_files_spec.rb +0 -0
  28. data/spec/rails_app_spec/matchers/special/have_app_config_spec.rb +0 -0
  29. data/spec/rails_app_spec/matchers/special/have_gem_spec.rb +0 -0
  30. data/spec/rails_app_spec/matchers/special/have_gems_spec.rb +0 -0
  31. metadata +52 -13
data/README.markdown CHANGED
@@ -24,11 +24,24 @@ Usage example (teaser):
24
24
  klass.should have_method :index
25
25
  end
26
26
  end
27
+
28
+ Rails.root.should have_view_dirs :person, :post, :blog
29
+
30
+ Rails.root.should have_model_dirs :admin, :editor
31
+
32
+ Rails.root.should have_controller_files :person, :post, :blog
33
+
34
+ Rails.root.should have_stylesheet_files :light, :basic, :dark
35
+ Rails.root.should have_javascript_files :form_validation, :effects
27
36
  end
28
37
  </pre>
29
38
 
30
39
  This library takes advantage of *code-spec*, *file-spec* and other essential spec extensions I have created ;)
31
40
 
41
+ ## TODO
42
+
43
+ Create specs for the special file matchers to make sure they work for all edge cases!
44
+
32
45
  ## Note on Patches/Pull Requests
33
46
 
34
47
  * Fork the project.
data/Rakefile CHANGED
@@ -7,9 +7,10 @@ begin
7
7
  gem.email = "kmandrup@gmail.com"
8
8
  gem.homepage = "http://github.com/kristianmandrup/rails-app-spec"
9
9
  gem.authors = ["Kristian Mandrup"]
10
- gem.add_dependency "rspec", "~> 2.0.0"
10
+ gem.add_dependency "rspec", "~> 2.0.0.beta.22"
11
11
  gem.add_dependency "require_all", "~> 1.1.0"
12
12
  gem.add_dependency "rails3_artifactor", "~> 0.1.4"
13
+ gem.add_dependency "sugar-high", "~> 0.2.6"
13
14
  gem.add_dependency "code-spec", "~> 0.2.1"
14
15
  gem.add_dependency "file-spec", "~> 0.1.1"
15
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.7
@@ -3,6 +3,8 @@ require 'require_all'
3
3
  require 'code-spec'
4
4
  require 'file-spec'
5
5
  require 'active_support/inflector'
6
+ require 'sugar-high/array'
7
+ require 'sugar-high/arguments'
6
8
 
7
9
  require 'rails_app_spec/namespaces'
8
10
  require 'rails_app_spec/rspec'
@@ -2,101 +2,22 @@
2
2
 
3
3
  module RSpec::RailsApp::Artifact
4
4
  module Matchers
5
- class HaveArtifact < RSpec::RubyContentMatcher
6
-
7
- # include ::Rails3::Assist::Directory
8
-
9
- # include Rails::Migration::Assist::ClassMethods
5
+ class HaveArtifact < RSpec::RubyContentMatcher
10
6
  include Rails3::Assist::Artifact::FileName
11
- # include ::Rails3::Assist::Migration::FileName
12
-
13
- attr_accessor :artifact_type, :artifact_name, :class_type, :content
14
- # class
15
- attr_accessor :name, :type, :postfix
16
- # subclass
17
- attr_accessor :superclass
18
-
19
- attr_accessor :folder, :action, :view_ext
20
-
21
- attr_accessor :artifact_found
22
-
23
- SUPERCLASS_MAP = {
24
- :observer => 'ActiveRecord::Observer',
25
- :mailer => 'ActionMailer::Base',
26
- :migration => 'ActiveRecord::Migration'
27
- }
28
-
29
- POSTFIX = [:helper, :observer, :controller, :mailer]
30
-
31
- def has_postfix? key
32
- POSTFIX.include? key
33
- end
7
+ include Artifact::Matcher::Helper
34
8
 
35
9
  def initialize(name, artifact_type)
36
- self.artifact_type = artifact_type
37
-
38
10
  extend "Rails3::Assist::Artifact::#{artifact_type.to_s.camelize}".constantize
39
-
40
- if name.kind_of? Hash
41
- view_options = name
42
- self.folder = view_options[:folder]
43
- self.action = view_options[:action]
44
- self.view_ext = view_options[:view_ext]
45
- self.artifact_type = :view
46
- return nil
47
- end
48
-
49
- self.postfix = artifact_type.to_s.camelize if has_postfix? artifact_type
50
- self.artifact_name = name.to_s.downcase
51
- self.name = name.to_s.camelize
52
11
 
53
- case artifact_type
54
- when :helper, :controller
55
- # artifact class check
56
- self.class_type = :class
57
- self.type = :class
58
- super name
59
- when :observer, :migration, :mailer
60
- self.class_type = :subclass
61
- # artifact subclass check
62
- self.superclass = SUPERCLASS_MAP[artifact_type]
63
- super name
64
- when :model
65
- # check class == name
66
- self.class_type = :class
67
- super name
68
- end
12
+ parse_name name
13
+ parse_type artifact_type
14
+ super name if artifact_type != :view
69
15
  end
70
16
 
71
17
  def matches?(root_path, &block)
72
18
  @root_path = root_path
73
- artifact_found = case artifact_type
74
- when :view
75
- find_view_method = "#{artifact_type}_file_name"
76
- File.expand_path(send find_view_method, folder, action, view_ext, :root_path => root_path)
77
- else
78
- find_existing_artifact_method = "existing_#{artifact_type}_file"
79
- if respond_to? find_existing_artifact_method
80
- begin
81
- send find_existing_artifact_method, artifact_name, artifact_type, :root_path => root_path
82
- rescue Exception => e
83
- @error_msg = e.message
84
- @trace = e.backtrace.join "\n"
85
- nil
86
- end
87
- else
88
- raise "The method ##{find_existing_artifact_method} to find the artifact was not available"
89
- end
90
- end
91
- if !artifact_found
92
- self.artifact_found = '[unknown]'
93
- return nil
94
- end
95
-
96
- @file_found = File.file?(artifact_found)
97
- return nil if !@file_found
98
-
99
- artifact_found = File.expand_path(artifact_found)
19
+ artifact_found = find_artifact
20
+ return nil if !artifact_found
100
21
 
101
22
  # check file content for class or subclass
102
23
  self.content = File.read(artifact_found)
@@ -106,47 +27,7 @@ module RSpec::RailsApp::Artifact
106
27
  return true
107
28
  end
108
29
  super content, &block
109
- end
110
-
111
- # TODO: Refactor, make DRY
112
- def main_expr
113
- # determine which regexp to use: class or subclass
114
- case class_type
115
- when :subclass
116
- 'class' + SPACES + "#{name}#{postfix}" + OPT_SPACES + '<' + OPT_SPACES + "#{superclass}" + ANY_GROUP
117
- when :class
118
- "#{type}" + SPACES + "#{name}#{postfix}" + SPACES + ANY_GROUP
119
- else
120
- raise "Class type must be either :class or :subclass, was #{class_type}"
121
- end
122
- end
123
-
124
- def alt_end
125
- 'class'
126
- end
127
-
128
- def should_be_msg
129
- case class_type
130
- when :subclass
131
- "have the name: #{name}#{postfix} and be a subclass of: #{superclass}"
132
- when :class
133
- "have the name: #{name}#{postfix}"
134
- else
135
- raise "Class type must be either :class or :subclass, was #{class_type}" if artifact_type != :view
136
- end
137
- end
138
-
139
- def failure_message
140
- return "Expected the #{artifact_type} #{artifact_name} to exist at #{artifact_found} (root = #{@root_path}), but it didn't.\nError: #{@error_msg}.\n\nTrace:\n #{@trace}" if !@file_found
141
- puts "Content: #{content}"
142
- "Expected the file: #{artifact_name} to have a #{artifact_type} class. The class should #{should_be_msg}"
143
- end
144
-
145
- def negative_failure_message
146
- return "Did not expect the #{artifact_type} #{artifact_name} to exist at #{artifact_found}, but it did" if !@file_found
147
- puts "Content: #{content}"
148
- "Did not expected the file: #{artifact_name} to have a #{artifact_type} class. The class should not #{should_be_msg}"
149
- end
30
+ end
150
31
  end
151
32
 
152
33
  def have_artifact(relative, type = nil)
@@ -0,0 +1,78 @@
1
+ # Combines artifact file exist check with class check!
2
+ module RSpec::RailsApp::Artifact
3
+ module Matchers
4
+ class HaveArtifacts < RSpec::RubyContentMatcher
5
+
6
+ include Rails3::Assist::Artifact::FileName
7
+ include ArtifactFile::Matcher::Helper
8
+ include Artifact::Matcher::Helper
9
+
10
+ attr_reader :names
11
+
12
+ def initialize(artifact_type, *names)
13
+ extend "Rails3::Assist::Artifact::#{artifact_type.to_s.camelize}".constantize
14
+
15
+ @names = names
16
+ parse_type artifact_type
17
+ if artifact_type == :view
18
+ handle_view artifact_type, names
19
+ else
20
+ super name
21
+ end
22
+ end
23
+
24
+ def matches?(root_path, &block)
25
+ @root_path = root_path
26
+
27
+ names.to_strings.each do |name|
28
+ parse_name name
29
+ artifact_found = find_artifact
30
+
31
+ # check file content for class or subclass
32
+ self.content = File.read(artifact_found)
33
+
34
+ res = if artifact_type == :view
35
+ true
36
+ else
37
+ super content
38
+ end
39
+ return false if !res
40
+ end
41
+ yield if block
42
+ true
43
+ end
44
+
45
+ protected
46
+
47
+ def parse_name name
48
+ if name.kind_of? Hash
49
+ self.action = name
50
+ return nil
51
+ end
52
+ self.artifact_name = name.to_s.downcase
53
+ self.name = name.to_s.camelize
54
+ end
55
+ end
56
+
57
+ def have_artifacts(type, *names)
58
+ HaveArtifacts.new(type, *names)
59
+ end
60
+ alias_method :contain_artifact, :have_artifact
61
+
62
+ (::Rails3::Assist.artifacts - [:view]).each do |name|
63
+ plural_name = name.to_s.pluralize
64
+ class_eval %{
65
+ def have_#{plural_name} *names
66
+ have_artifacts :#{name}, *names
67
+ end
68
+ alias_method :contain_#{plural_name}, :have_#{plural_name}
69
+ }
70
+ end
71
+
72
+ def have_views folder, *args
73
+ have_artifacts :view, *args
74
+ end
75
+ alias_method :contain_view, :have_view
76
+ end
77
+ end
78
+
@@ -1,62 +1,34 @@
1
1
  module RSpec::RailsApp::ArtifactFile
2
2
  module Matchers
3
3
  class HaveRailsArtifactFile
4
-
5
- # include Rails::Migration::Assist::ClassMethods
6
4
  include ::Rails3::Assist::Artifact::FileName
7
- # include ::Rails::Assist::Migration::FileName
8
5
 
9
6
  attr_accessor :name, :artifact_type, :artifact_name
10
-
11
7
  attr_accessor :folder, :action, :view_ext
12
8
 
9
+ include ArtifactFile::Matcher::Helper
10
+
13
11
  def initialize(name, artifact_type = nil)
14
12
  self.artifact_type = artifact_type
15
13
 
16
14
  extend "Rails3::Assist::Artifact::#{artifact_type.to_s.camelize}".constantize
17
15
 
18
16
  if name.kind_of? Hash
19
- view_options = name
20
- self.folder = view_options[:folder]
21
- self.action = view_options[:action]
22
- self.view_ext = view_options[:view_ext]
23
- self.artifact_type = :view
17
+ set_view name
24
18
  return nil
25
19
  end
26
20
  self.artifact_name = name.to_s
27
21
  end
28
22
 
29
23
  def matches?(root_path, &block)
30
- self.artifact_name = case artifact_type
31
- when :view
32
- find_view_method = "#{artifact_type}_file_name"
33
- File.expand_path(send find_view_method, folder, action, view_ext, :root_path => root_path)
34
- else
35
- find_existing_artifact_method = "existing_#{artifact_type}_file"
36
- if respond_to? find_existing_artifact_method
37
- send find_existing_artifact_method, artifact_name, artifact_type, :root_path => root_path
38
- else
39
- raise "The method ##{find_existing_artifact_method} to find the artifact was not available"
40
- end
41
- end
42
-
43
- # puts "artifact_name: #{artifact_name}"
24
+ self.artifact_name = get_artifact_name
44
25
 
45
26
  match = File.file? artifact_name
46
27
  if block && match
47
28
  yield File.read(artifact_name)
48
29
  end
49
30
  match
50
- end
51
-
52
- def failure_message
53
- "Expected the #{artifact_type} #{artifact_name} to exist, but it didn't"
54
- end
55
-
56
- def negative_failure_message
57
- "Did not expect the #{artifact_type} #{artifact_name} to exist, but it did"
58
- end
59
-
31
+ end
60
32
  end
61
33
 
62
34
  def have_rails_artifact_file(relative, artifact_type = nil)
@@ -0,0 +1,33 @@
1
+ module RSpec::RailsApp::ArtifactFile
2
+ module Matchers
3
+ class HaveRailsArtifactFiles
4
+ include ::Rails3::Assist::Artifact::FileName
5
+ include ArtifactFile::Matcher::Helper
6
+
7
+ def initialize(artifact_type, *names)
8
+ @names = names
9
+ extend "Rails3::Assist::Artifact::#{artifact_type.to_s.camelize}".constantize
10
+
11
+ handle_view artifact_type, names
12
+
13
+ self.artifact_type = artifact_type
14
+ self.artifact_name = name.to_s
15
+ end
16
+
17
+ def matches?(root_path, &block)
18
+ names.to_strings.each do |name|
19
+ self.artifact_name = get_artifact_name
20
+ return false if !File.file?(artifact_name)
21
+ end
22
+ yield if block
23
+ true
24
+ end
25
+ end
26
+
27
+ def have_rails_artifact_files(artifact_type, *names)
28
+ HaveRailsArtifactFiles.new(artifact_type, *names)
29
+ end
30
+ alias_method :contain_rails_artifact_files, :have_rails_artifact_files
31
+ end
32
+ end
33
+
@@ -0,0 +1,56 @@
1
+ module ArtifactFile
2
+ module Matcher
3
+ end
4
+ end
5
+
6
+ module ArtifactFile::Matcher
7
+ module Helper
8
+ attr_accessor :name, :artifact_type, :artifact_name
9
+ attr_accessor :folder, :action, :view_ext
10
+ attr_reader :names, :root_path
11
+
12
+ def set_view name
13
+ view_options = name
14
+ self.folder = view_options[:folder]
15
+ self.action = view_options[:action]
16
+ self.view_ext = view_options[:view_ext]
17
+ self.artifact_type = :view
18
+ end
19
+
20
+ def handle_view artifact_type, names
21
+ if artifact_type == :view
22
+ lang_option = last_arg({:lang => 'erb.html'}, names)
23
+ raise ArgumentException, ':folder option must be specified in the last hash argument for #have_views' if !lang_option[:folder]
24
+ self.folder = lang_option[:folder]
25
+ self.view_ext = lang_option[:lang] || {:lang => 'erb.html'}
26
+ end
27
+ end
28
+
29
+ def get_artifact_name
30
+ case artifact_type
31
+ when :view
32
+ find_view_method = "#{artifact_type}_file_name"
33
+ File.expand_path(send find_view_method, folder, action, view_ext, :root_path => root_path)
34
+ else
35
+ find_existing_artifact_method = "existing_#{artifact_type}_file"
36
+ if respond_to? find_existing_artifact_method
37
+ send find_existing_artifact_method, artifact_name, artifact_type, :root_path => root_path
38
+ else
39
+ raise "The method ##{find_existing_artifact_method} to find the artifact was not available"
40
+ end
41
+ end
42
+ end
43
+
44
+ def msg
45
+ "the #{artifact_type} #{artifact_name} to exist"
46
+ end
47
+
48
+ def failure_message
49
+ "Expected #{msg}"
50
+ end
51
+
52
+ def negative_failure_message
53
+ "Did not expect #{msg}"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,134 @@
1
+ module Artifact
2
+ module Matcher
3
+ end
4
+ end
5
+
6
+ module Artifact::Matcher
7
+ module Helper
8
+ attr_accessor :artifact_type, :artifact_name, :class_type, :content
9
+ # class
10
+ attr_accessor :name, :type, :postfix
11
+ # subclass
12
+ attr_accessor :superclass
13
+ attr_accessor :folder, :action, :view_ext
14
+ attr_accessor :artifact_found
15
+ attr_reader :root_path
16
+
17
+ SUPERCLASS_MAP = {
18
+ :observer => 'ActiveRecord::Observer',
19
+ :mailer => 'ActionMailer::Base',
20
+ :migration => 'ActiveRecord::Migration'
21
+ }
22
+
23
+ POSTFIX = [:helper, :observer, :controller, :mailer]
24
+
25
+ def has_postfix? key
26
+ POSTFIX.include? key
27
+ end
28
+
29
+ def parse_type artifact_type
30
+ self.artifact_type = artifact_type
31
+ self.postfix = artifact_type.to_s.camelize if has_postfix? artifact_type
32
+ case artifact_type
33
+ when :helper, :controller
34
+ # artifact class check
35
+ self.class_type = :class
36
+ self.type = :class
37
+ when :observer, :migration, :mailer
38
+ self.class_type = :subclass
39
+ # artifact subclass check
40
+ self.superclass = SUPERCLASS_MAP[artifact_type]
41
+ when :model
42
+ # check class == name
43
+ self.class_type = :class
44
+ end
45
+ end
46
+
47
+ def parse_name name
48
+ if name.kind_of? Hash
49
+ view_options = name
50
+ self.folder = view_options[:folder]
51
+ self.action = view_options[:action]
52
+ self.view_ext = view_options[:view_ext]
53
+ self.artifact_type = :view
54
+ return nil
55
+ end
56
+ self.artifact_name = name.to_s.downcase
57
+ self.name = name.to_s.camelize
58
+ end
59
+
60
+ def find_artifact
61
+ artifact_found = case artifact_type
62
+ when :view
63
+ find_view_method = "#{artifact_type}_file_name"
64
+ File.expand_path(send find_view_method, folder, action, view_ext, :root_path => root_path)
65
+ else
66
+ find_existing_artifact_method = "existing_#{artifact_type}_file"
67
+ if respond_to? find_existing_artifact_method
68
+ begin
69
+ send find_existing_artifact_method, artifact_name, artifact_type, :root_path => root_path
70
+ rescue Exception => e
71
+ @error_msg = e.message
72
+ @trace = e.backtrace.join "\n"
73
+ nil
74
+ end
75
+ else
76
+ raise "The method ##{find_existing_artifact_method} to find the artifact was not available"
77
+ end
78
+ end
79
+ if !artifact_found
80
+ self.artifact_found = '[unknown]'
81
+ return nil
82
+ end
83
+
84
+ @file_found = File.file?(artifact_found)
85
+ return nil if !@file_found
86
+
87
+ File.expand_path(artifact_found)
88
+ end
89
+
90
+ SPACES = '\s+'
91
+ OPT_SPACES = '\s*'
92
+ ANY_GROUP = '(.*)'
93
+
94
+ # TODO: Refactor, make DRY
95
+ def main_expr
96
+ # determine which regexp to use: class or subclass
97
+ case class_type
98
+ when :subclass
99
+ 'class' + SPACES + "#{name}#{postfix}" + OPT_SPACES + '<' + OPT_SPACES + "#{superclass}" + ANY_GROUP
100
+ when :class
101
+ "#{type}" + SPACES + "#{name}#{postfix}" + SPACES + ANY_GROUP
102
+ else
103
+ raise "Class type must be either :class or :subclass, was #{class_type}"
104
+ end
105
+ end
106
+
107
+ def alt_end
108
+ 'class'
109
+ end
110
+
111
+ def should_be_msg
112
+ case class_type
113
+ when :subclass
114
+ "have the name: #{name}#{postfix} and be a subclass of: #{superclass}"
115
+ when :class
116
+ "have the name: #{name}#{postfix}"
117
+ else
118
+ raise "Class type must be either :class or :subclass, was #{class_type}" if artifact_type != :view
119
+ end
120
+ end
121
+
122
+ def failure_message
123
+ return "Expected the #{artifact_type} #{artifact_name} to exist at #{artifact_found} (root = #{@root_path}), but it didn't.\nError: #{@error_msg}.\n\nTrace:\n #{@trace}" if !@file_found
124
+ puts "Content: #{content}"
125
+ "Expected the file: #{artifact_name} to have a #{artifact_type} class. The class should #{should_be_msg}"
126
+ end
127
+
128
+ def negative_failure_message
129
+ return "Did not expect the #{artifact_type} #{artifact_name} to exist at #{artifact_found}, but it did" if !@file_found
130
+ puts "Content: #{content}"
131
+ "Did not expected the file: #{artifact_name} to have a #{artifact_type} class. The class should not #{should_be_msg}"
132
+ end
133
+ end
134
+ end
@@ -0,0 +1 @@
1
+ require_all File.dirname(__FILE__) + '/artifact/shared'
@@ -0,0 +1,43 @@
1
+ module RSpec::RailsApp::Directory
2
+ module Matchers
3
+ class HaveArtifactDirs
4
+
5
+ attr_accessor :artifact_type, :dir, :dir_name, :dirs
6
+
7
+ def initialize artifact_type, *dirs
8
+ @artifact_type = artifact_type
9
+ @dirs = dirs
10
+ end
11
+
12
+ def matches?(obj, &block)
13
+ dirs.to_strings.each do |dir_name|
14
+ @dir_name = dir_name
15
+ @dir = File.join(send :"#{artifact_type}_dir", dir_name)
16
+ return false if !File.directory?(dir)
17
+ end
18
+ yield if block
19
+ true
20
+ end
21
+
22
+ def msg
23
+ "Rails app to have the #{artifact_type} dir: #{dir_name}"
24
+ end
25
+
26
+ def failure_message
27
+ "Expected #{msg}"
28
+ end
29
+
30
+ def negative_failure_message
31
+ "Did not expect #{msg}"
32
+ end
33
+ end
34
+
35
+ ::Rails3::Assist::Directory::App.app_directories.each do |name|
36
+ class_eval %{
37
+ def have_#{name}_dirs *names
38
+ have_artifact_dirs :#{name}, *names
39
+ end
40
+ }
41
+ end
42
+ end
43
+ end
@@ -1,4 +1,4 @@
1
- module RSpec::RailsApp::Dir
1
+ module RSpec::RailsApp::Directory
2
2
  module Matchers
3
3
  class HaveRailsDir
4
4
 
@@ -0,0 +1,34 @@
1
+ module RSpec::RailsApp::Directory
2
+ module Matchers
3
+ class HaveRailsDirs
4
+
5
+ attr_accessor :dir, :dir_name, :dirs
6
+
7
+ def initialize *dirs
8
+ @dirs = dirs
9
+ end
10
+
11
+ def matches?(obj, &block)
12
+ dirs.to_strings.each do |dir_name|
13
+ @dir_name = dir_name
14
+ @dir = send :"#{dir_name}_dir"
15
+ return false if !File.directory?(dir)
16
+ end
17
+ yield if block
18
+ true
19
+ end
20
+
21
+ def failure_message
22
+ "Expected Rails app to have dir: #{dir_name}, but it didn't"
23
+ end
24
+
25
+ def negative_failure_message
26
+ "Did not expected Rails app to have dir: #{dir_name}, but it did"
27
+ end
28
+ end
29
+
30
+ def have_rails_dirs *dirs
31
+ HaveRailsDirs.new *dirs
32
+ end
33
+ end
34
+ end
@@ -1,10 +1,11 @@
1
+ require 'rails_app_spec/matchers/file/rails_file_helper'
2
+
1
3
  module RSpec::RailsApp::File
2
4
  module Matchers
3
5
  class HaveRailsFile
4
6
  include ::Rails3::Assist::Artifact
7
+ include RailsFile::Matcher::Helper
5
8
 
6
- attr_reader :file, :type, :name
7
-
8
9
  def initialize(name, type = nil)
9
10
  @type = type if type
10
11
  @name = name
@@ -13,15 +14,7 @@ module RSpec::RailsApp::File
13
14
  def matches?(obj, &block)
14
15
  @file = type ? send(:"#{type}_file", name) : send(:"#{name}_file")
15
16
  File.file? file
16
- end
17
-
18
- def failure_message
19
- "Expected Rails app to have file: #{file}, but it didn't"
20
- end
21
-
22
- def negative_failure_message
23
- "Did not expected Rails app to have file: #{file}, but it did"
24
- end
17
+ end
25
18
  end
26
19
 
27
20
  def have_rails_file(type = nil)
@@ -0,0 +1,39 @@
1
+ require 'rails_app_spec/matchers/file/rails_file_helper'
2
+
3
+ module RSpec::RailsApp::File
4
+ module Matchers
5
+ class HaveRailsFiles
6
+ include ::Rails3::Assist::Artifact
7
+ include RailsFile::Matcher::Helper
8
+
9
+ attr_reader :names
10
+
11
+ def initialize(type, *names)
12
+ @type = type
13
+ @names = names
14
+ end
15
+
16
+ def matches?(obj, &block)
17
+ names.to_strings.each do |name|
18
+ @name = name
19
+ @file = send(:"#{type}_file", name)
20
+ return false if !File.file?(file)
21
+ end
22
+ yield if block
23
+ true
24
+ end
25
+ end
26
+
27
+ def have_rails_files(type, *names)
28
+ HaveRailsFiles.new(type, *names)
29
+ end
30
+
31
+ [:initializer, :db, :migration, :locale, :javascript, :stylesheet].each do |name|
32
+ class_eval %{
33
+ def have_#{name}_files *names
34
+ have_rails_files :#{name}, *names
35
+ end
36
+ }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ module RailsFile
2
+ module Matcher
3
+ module Helper
4
+ attr_reader :file, :type, :name
5
+
6
+ def msg
7
+ "Rails app to have the #{type} file called #{name} at: #{file}"
8
+ end
9
+
10
+ def failure_message
11
+ "Expected #{msg}"
12
+ end
13
+
14
+ def negative_failure_message
15
+ "Did not expect #{msg}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,65 @@
1
+ # open application_file
2
+ # see if there is the config.[statement] = [expr]
3
+
4
+ require 'sugar-high/kind_of'
5
+
6
+ module RSpec::RailsApp::Content
7
+ module Matchers
8
+ class HaveGem
9
+ extend Rails3::Assist::UseMacro
10
+ use_helpers :file
11
+
12
+ attr_reader :name, :version, :options
13
+
14
+ def initialize *args
15
+ raise ArgumentException, "First argument must name the gem" if !args.first.kind_of_label?
16
+ @name = args.delete_at(0)
17
+ return if args.size == 0 || !args[1].kind_of_label?
18
+
19
+ @version = args.delete_at(1)
20
+ @options = {}
21
+
22
+ return if args.empty?
23
+ raise ArgumentException, "Last argument of gem statement must be a n options Hash" if !args.last.kind_of? Hash
24
+ @options = args.last
25
+ end
26
+
27
+ # TODO: relative to root_path ?
28
+ def matches?(root_path=nil)
29
+ content = read_gemfile
30
+ return nil if content.empty?
31
+ (content =~ /gem\s+#{name_expr}#{version_expr}/)
32
+ end
33
+
34
+ def name_expr
35
+ "('|\")" + name + '\1'
36
+ end
37
+
38
+ def version_expr
39
+ '\s*,\s*' + "('|\")" + name + '\2' if version
40
+ end
41
+
42
+ def msg
43
+ "the Gemfile to have a gem statement: gem '#{name}'#{version_txt}'"
44
+ end
45
+
46
+ def version_txt
47
+ version ? ", '#{version}'" : ""
48
+ end
49
+
50
+ def failure_message
51
+ "Expected #{msg}"
52
+ end
53
+
54
+ def negative_failure_message
55
+ "Did not expect #{msg}"
56
+ end
57
+ end
58
+
59
+ # config.autoload_paths += %W(#{Rails.root}/lib)
60
+ # have_app_config :autoload_paths => '%W(#{Rails.root}/lib)', :op => '+='
61
+ def have_gem *args
62
+ HaveGem.new *args
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,56 @@
1
+ # open application_file
2
+ # see if there is the config.[statement] = [expr]
3
+
4
+ require 'sugar-high/kind_of'
5
+ require 'sugar-high/array'
6
+
7
+ module RSpec::RailsApp::Content
8
+ module Matchers
9
+ class HaveGems
10
+ extend Rails3::Assist::UseMacro
11
+ use_helpers :file
12
+
13
+ attr_reader :names, :name
14
+
15
+ def initialize *names
16
+ @names = names.to_strings
17
+ end
18
+
19
+ # TODO: relative to root_path ?
20
+ def matches?(root_path=nil)
21
+ content = read_gemfile
22
+ return nil if content.empty?
23
+ names.each do |name|
24
+ (content =~ /gem\s+#{name_expr(name)}/)
25
+ end
26
+ end
27
+
28
+ def name_expr gem_name
29
+ @name = gem_name
30
+ "('|\")" + gem_name + '\1'
31
+ end
32
+
33
+ def msg
34
+ "the Gemfile to have a gem statement: gem '#{name}'"
35
+ end
36
+
37
+ def version_txt
38
+ version ? ", '#{version}'" : ""
39
+ end
40
+
41
+ def failure_message
42
+ "Expected #{msg}"
43
+ end
44
+
45
+ def negative_failure_message
46
+ "Did not expect #{msg}"
47
+ end
48
+ end
49
+
50
+ # config.autoload_paths += %W(#{Rails.root}/lib)
51
+ # have_app_config :autoload_paths => '%W(#{Rails.root}/lib)', :op => '+='
52
+ def have_gems *names
53
+ HaveGems.new *names
54
+ end
55
+ end
56
+ end
@@ -0,0 +1 @@
1
+ require_all File.dirname(__FILE__) + '/matchers'
@@ -1,6 +1,6 @@
1
1
  RSpec.configure do |config|
2
2
  config.include RSpec::RailsApp::File::Matchers
3
- config.include RSpec::RailsApp::Dir::Matchers
3
+ config.include RSpec::RailsApp::Directory::Matchers
4
4
  config.include RSpec::RailsApp::Content::Matchers
5
5
  config.include RSpec::RailsApp::Artifact::Matchers
6
6
  config.include RSpec::RailsApp::ArtifactClass::Matchers
@@ -1,3 +1,3 @@
1
1
  require 'rspec/core'
2
- require_all File.dirname(__FILE__) + '/matchers'
2
+ require 'rails_app_spec/matchers'
3
3
  require_all File.dirname(__FILE__) + '/rspec'
@@ -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.5"
8
+ s.version = "0.2.7"
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-13}
12
+ s.date = %q{2010-09-14}
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 = [
@@ -25,14 +25,26 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/rails-app-spec.rb",
28
+ "lib/rails_app_spec/matchers.rb",
29
+ "lib/rails_app_spec/matchers/artifact.rb",
28
30
  "lib/rails_app_spec/matchers/artifact/class/have_artifact_class.rb",
29
31
  "lib/rails_app_spec/matchers/artifact/class/have_artifact_subclass.rb",
30
32
  "lib/rails_app_spec/matchers/artifact/have_artifact.rb",
31
33
  "lib/rails_app_spec/matchers/artifact/have_artifact_file.rb",
34
+ "lib/rails_app_spec/matchers/artifact/have_artifacts.rb",
32
35
  "lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb",
33
- "lib/rails_app_spec/matchers/file/have_rails_dir.rb",
36
+ "lib/rails_app_spec/matchers/artifact/have_rails_artifact_files.rb",
37
+ "lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb",
38
+ "lib/rails_app_spec/matchers/artifact/shared/artifact_helper.rb",
39
+ "lib/rails_app_spec/matchers/directory/have_artifact_dirs.rb",
40
+ "lib/rails_app_spec/matchers/directory/have_rails_dir.rb",
41
+ "lib/rails_app_spec/matchers/directory/have_rails_dirs.rb",
34
42
  "lib/rails_app_spec/matchers/file/have_rails_file.rb",
43
+ "lib/rails_app_spec/matchers/file/have_rails_files.rb",
44
+ "lib/rails_app_spec/matchers/file/rails_file_helper.rb",
35
45
  "lib/rails_app_spec/matchers/special/have_app_config.rb",
46
+ "lib/rails_app_spec/matchers/special/have_gem.rb",
47
+ "lib/rails_app_spec/matchers/special/have_gems.rb",
36
48
  "lib/rails_app_spec/namespaces.rb",
37
49
  "lib/rails_app_spec/rspec.rb",
38
50
  "lib/rails_app_spec/rspec/configure.rb",
@@ -47,8 +59,13 @@ Gem::Specification.new do |s|
47
59
  "spec/rails_app_spec/matchers/artifact/model_spec.rb",
48
60
  "spec/rails_app_spec/matchers/artifact/observer_spec.rb",
49
61
  "spec/rails_app_spec/matchers/artifact/view_spec.rb",
50
- "spec/rails_app_spec/matchers/file/have_dir_spec.rb",
51
- "spec/rails_app_spec/matchers/file/have_file_spec.rb",
62
+ "spec/rails_app_spec/matchers/directory/have_rails_dir_spec.rb",
63
+ "spec/rails_app_spec/matchers/directory/have_rails_dirs_spec.rb",
64
+ "spec/rails_app_spec/matchers/file/have_rails_file_spec.rb",
65
+ "spec/rails_app_spec/matchers/file/have_rails_files_spec.rb",
66
+ "spec/rails_app_spec/matchers/special/have_app_config_spec.rb",
67
+ "spec/rails_app_spec/matchers/special/have_gem_spec.rb",
68
+ "spec/rails_app_spec/matchers/special/have_gems_spec.rb",
52
69
  "spec/spec_helper.rb"
53
70
  ]
54
71
  s.homepage = %q{http://github.com/kristianmandrup/rails-app-spec}
@@ -65,8 +82,13 @@ Gem::Specification.new do |s|
65
82
  "spec/rails_app_spec/matchers/artifact/model_spec.rb",
66
83
  "spec/rails_app_spec/matchers/artifact/observer_spec.rb",
67
84
  "spec/rails_app_spec/matchers/artifact/view_spec.rb",
68
- "spec/rails_app_spec/matchers/file/have_dir_spec.rb",
69
- "spec/rails_app_spec/matchers/file/have_file_spec.rb",
85
+ "spec/rails_app_spec/matchers/directory/have_rails_dir_spec.rb",
86
+ "spec/rails_app_spec/matchers/directory/have_rails_dirs_spec.rb",
87
+ "spec/rails_app_spec/matchers/file/have_rails_file_spec.rb",
88
+ "spec/rails_app_spec/matchers/file/have_rails_files_spec.rb",
89
+ "spec/rails_app_spec/matchers/special/have_app_config_spec.rb",
90
+ "spec/rails_app_spec/matchers/special/have_gem_spec.rb",
91
+ "spec/rails_app_spec/matchers/special/have_gems_spec.rb",
70
92
  "spec/spec_helper.rb"
71
93
  ]
72
94
 
@@ -75,22 +97,25 @@ Gem::Specification.new do |s|
75
97
  s.specification_version = 3
76
98
 
77
99
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
78
- s.add_runtime_dependency(%q<rspec>, ["~> 2.0.0"])
100
+ s.add_runtime_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
79
101
  s.add_runtime_dependency(%q<require_all>, ["~> 1.1.0"])
80
102
  s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.1.4"])
103
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.6"])
81
104
  s.add_runtime_dependency(%q<code-spec>, ["~> 0.2.1"])
82
105
  s.add_runtime_dependency(%q<file-spec>, ["~> 0.1.1"])
83
106
  else
84
- s.add_dependency(%q<rspec>, ["~> 2.0.0"])
107
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
85
108
  s.add_dependency(%q<require_all>, ["~> 1.1.0"])
86
109
  s.add_dependency(%q<rails3_artifactor>, ["~> 0.1.4"])
110
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.6"])
87
111
  s.add_dependency(%q<code-spec>, ["~> 0.2.1"])
88
112
  s.add_dependency(%q<file-spec>, ["~> 0.1.1"])
89
113
  end
90
114
  else
91
- s.add_dependency(%q<rspec>, ["~> 2.0.0"])
115
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
92
116
  s.add_dependency(%q<require_all>, ["~> 1.1.0"])
93
117
  s.add_dependency(%q<rails3_artifactor>, ["~> 0.1.4"])
118
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.6"])
94
119
  s.add_dependency(%q<code-spec>, ["~> 0.2.1"])
95
120
  s.add_dependency(%q<file-spec>, ["~> 0.1.1"])
96
121
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 7
9
+ version: 0.2.7
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-13 00:00:00 +02:00
17
+ date: 2010-09-14 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -29,7 +29,9 @@ dependencies:
29
29
  - 2
30
30
  - 0
31
31
  - 0
32
- version: 2.0.0
32
+ - beta
33
+ - 22
34
+ version: 2.0.0.beta.22
33
35
  type: :runtime
34
36
  version_requirements: *id001
35
37
  - !ruby/object:Gem::Dependency
@@ -63,9 +65,24 @@ dependencies:
63
65
  type: :runtime
64
66
  version_requirements: *id003
65
67
  - !ruby/object:Gem::Dependency
66
- name: code-spec
68
+ name: sugar-high
67
69
  prerelease: false
68
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
+ - 6
79
+ version: 0.2.6
80
+ type: :runtime
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: code-spec
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
69
86
  none: false
70
87
  requirements:
71
88
  - - ~>
@@ -76,11 +93,11 @@ dependencies:
76
93
  - 1
77
94
  version: 0.2.1
78
95
  type: :runtime
79
- version_requirements: *id004
96
+ version_requirements: *id005
80
97
  - !ruby/object:Gem::Dependency
81
98
  name: file-spec
82
99
  prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
100
+ requirement: &id006 !ruby/object:Gem::Requirement
84
101
  none: false
85
102
  requirements:
86
103
  - - ~>
@@ -91,7 +108,7 @@ dependencies:
91
108
  - 1
92
109
  version: 0.1.1
93
110
  type: :runtime
94
- version_requirements: *id005
111
+ version_requirements: *id006
95
112
  description: RSpec 2 matchers to spec the structure of your Rails 3 app
96
113
  email: kmandrup@gmail.com
97
114
  executables: []
@@ -110,14 +127,26 @@ files:
110
127
  - Rakefile
111
128
  - VERSION
112
129
  - lib/rails-app-spec.rb
130
+ - lib/rails_app_spec/matchers.rb
131
+ - lib/rails_app_spec/matchers/artifact.rb
113
132
  - lib/rails_app_spec/matchers/artifact/class/have_artifact_class.rb
114
133
  - lib/rails_app_spec/matchers/artifact/class/have_artifact_subclass.rb
115
134
  - lib/rails_app_spec/matchers/artifact/have_artifact.rb
116
135
  - lib/rails_app_spec/matchers/artifact/have_artifact_file.rb
136
+ - lib/rails_app_spec/matchers/artifact/have_artifacts.rb
117
137
  - lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb
118
- - lib/rails_app_spec/matchers/file/have_rails_dir.rb
138
+ - lib/rails_app_spec/matchers/artifact/have_rails_artifact_files.rb
139
+ - lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb
140
+ - lib/rails_app_spec/matchers/artifact/shared/artifact_helper.rb
141
+ - lib/rails_app_spec/matchers/directory/have_artifact_dirs.rb
142
+ - lib/rails_app_spec/matchers/directory/have_rails_dir.rb
143
+ - lib/rails_app_spec/matchers/directory/have_rails_dirs.rb
119
144
  - lib/rails_app_spec/matchers/file/have_rails_file.rb
145
+ - lib/rails_app_spec/matchers/file/have_rails_files.rb
146
+ - lib/rails_app_spec/matchers/file/rails_file_helper.rb
120
147
  - lib/rails_app_spec/matchers/special/have_app_config.rb
148
+ - lib/rails_app_spec/matchers/special/have_gem.rb
149
+ - lib/rails_app_spec/matchers/special/have_gems.rb
121
150
  - lib/rails_app_spec/namespaces.rb
122
151
  - lib/rails_app_spec/rspec.rb
123
152
  - lib/rails_app_spec/rspec/configure.rb
@@ -132,8 +161,13 @@ files:
132
161
  - spec/rails_app_spec/matchers/artifact/model_spec.rb
133
162
  - spec/rails_app_spec/matchers/artifact/observer_spec.rb
134
163
  - spec/rails_app_spec/matchers/artifact/view_spec.rb
135
- - spec/rails_app_spec/matchers/file/have_dir_spec.rb
136
- - spec/rails_app_spec/matchers/file/have_file_spec.rb
164
+ - spec/rails_app_spec/matchers/directory/have_rails_dir_spec.rb
165
+ - spec/rails_app_spec/matchers/directory/have_rails_dirs_spec.rb
166
+ - spec/rails_app_spec/matchers/file/have_rails_file_spec.rb
167
+ - spec/rails_app_spec/matchers/file/have_rails_files_spec.rb
168
+ - spec/rails_app_spec/matchers/special/have_app_config_spec.rb
169
+ - spec/rails_app_spec/matchers/special/have_gem_spec.rb
170
+ - spec/rails_app_spec/matchers/special/have_gems_spec.rb
137
171
  - spec/spec_helper.rb
138
172
  has_rdoc: true
139
173
  homepage: http://github.com/kristianmandrup/rails-app-spec
@@ -176,6 +210,11 @@ test_files:
176
210
  - spec/rails_app_spec/matchers/artifact/model_spec.rb
177
211
  - spec/rails_app_spec/matchers/artifact/observer_spec.rb
178
212
  - spec/rails_app_spec/matchers/artifact/view_spec.rb
179
- - spec/rails_app_spec/matchers/file/have_dir_spec.rb
180
- - spec/rails_app_spec/matchers/file/have_file_spec.rb
213
+ - spec/rails_app_spec/matchers/directory/have_rails_dir_spec.rb
214
+ - spec/rails_app_spec/matchers/directory/have_rails_dirs_spec.rb
215
+ - spec/rails_app_spec/matchers/file/have_rails_file_spec.rb
216
+ - spec/rails_app_spec/matchers/file/have_rails_files_spec.rb
217
+ - spec/rails_app_spec/matchers/special/have_app_config_spec.rb
218
+ - spec/rails_app_spec/matchers/special/have_gem_spec.rb
219
+ - spec/rails_app_spec/matchers/special/have_gems_spec.rb
181
220
  - spec/spec_helper.rb