rails-app-spec 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,7 +40,7 @@ This library takes advantage of *code-spec*, *file-spec* and other essential spe
40
40
 
41
41
  ## TODO
42
42
 
43
- Create specs for the special file matchers to make sure they work for all edge cases!
43
+ Finish specs for the file matchers including the special file matchers to make sure they work!
44
44
 
45
45
  ## Note on Patches/Pull Requests
46
46
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
@@ -10,13 +10,13 @@ module RSpec::RailsApp::ArtifactFile
10
10
 
11
11
  handle_view artifact_type, names
12
12
 
13
- self.artifact_type = artifact_type
14
- self.artifact_name = name.to_s
13
+ @artifact_type = artifact_type
15
14
  end
16
15
 
17
16
  def matches?(root_path, &block)
18
- names.to_strings.each do |name|
19
- self.artifact_name = get_artifact_name
17
+ names.to_strings.each do |name|
18
+ @artifact_name = name
19
+ @artifact_name = get_artifact_name
20
20
  return false if !File.file?(artifact_name)
21
21
  end
22
22
  yield if block
@@ -28,6 +28,20 @@ module RSpec::RailsApp::ArtifactFile
28
28
  HaveRailsArtifactFiles.new(artifact_type, *names)
29
29
  end
30
30
  alias_method :contain_rails_artifact_files, :have_rails_artifact_files
31
+
32
+ (::Rails3::Assist.artifacts - [:view]).each do |name|
33
+ class_eval %{
34
+ def have_#{name}_files *names
35
+ have_rails_artifact_files :#{name}, *names
36
+ end
37
+ alias_method :contain_#{name}_files, :have_#{name}_files
38
+ }
39
+ end
40
+
41
+ def have_view_files *args
42
+ have_rails_artifact_files :view, *args
43
+ end
44
+ alias_method :contain_view_files, :have_view_files
31
45
  end
32
46
  end
33
47
 
@@ -5,32 +5,53 @@ end
5
5
 
6
6
  module ArtifactFile::Matcher
7
7
  module Helper
8
- attr_accessor :name, :artifact_type, :artifact_name
9
- attr_accessor :folder, :action, :view_ext
8
+ include ::Rails3::Assist::Artifact::View::FileName
9
+
10
+ attr_reader :name, :artifact_type, :artifact_name
11
+ attr_reader :folder, :action, :view_ext
10
12
  attr_reader :names, :root_path
11
13
 
12
14
  def set_view name
13
15
  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
16
+ puts "view_options: #{view_options}"
17
+ @folder = view_options[:folder]
18
+ @action = view_options[:action]
19
+ @view_ext = view_options[:view_ext]
20
+ @artifact_type = :view
18
21
  end
19
22
 
20
23
  def handle_view artifact_type, names
21
24
  if artifact_type == :view
25
+ puts "handle view"
22
26
  lang_option = last_arg({:lang => 'erb.html'}, names)
23
27
  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'}
28
+ @folder = lang_option[:folder]
29
+ @view_ext = get_view_ext(lang_option[:lang] || :erb)
30
+
31
+ puts "folder: #{folder}, ext: #{view_ext}"
32
+ end
33
+ end
34
+
35
+ def get_view_ext(ext)
36
+ case ext.to_sym
37
+ when :erb
38
+ 'erb.html'
39
+ when :haml
40
+ 'haml.html'
41
+ else
42
+ ext.to_s
26
43
  end
27
44
  end
28
45
 
29
46
  def get_artifact_name
30
47
  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)
48
+ when :view
49
+ puts "args: #{folder}"
50
+ puts "args: #{artifact_name}"
51
+ #, #{action}"
52
+ path = send(:view_file_name, folder, artifact_name) #, view_ext, :root_path => root_path)
53
+ # puts "path: #{path}"
54
+ # File.expand_path(path)
34
55
  else
35
56
  find_existing_artifact_method = "existing_#{artifact_type}_file"
36
57
  if respond_to? find_existing_artifact_method
@@ -10,9 +10,9 @@ module Artifact::Matcher
10
10
  attr_accessor :name, :type, :postfix
11
11
  # subclass
12
12
  attr_accessor :superclass
13
- attr_accessor :folder, :action, :view_ext
14
- attr_accessor :artifact_found
15
- attr_reader :root_path
13
+
14
+ attr_reader :folder, :action, :view_ext
15
+ attr_reader :artifact_found, :root_path
16
16
 
17
17
  SUPERCLASS_MAP = {
18
18
  :observer => 'ActiveRecord::Observer',
@@ -27,34 +27,34 @@ module Artifact::Matcher
27
27
  end
28
28
 
29
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
30
+ @artifact_type = artifact_type
31
+ @postfix = artifact_type.to_s.camelize if has_postfix? artifact_type
32
32
  case artifact_type
33
33
  when :helper, :controller
34
34
  # artifact class check
35
- self.class_type = :class
36
- self.type = :class
35
+ @class_type = :class
36
+ @type = :class
37
37
  when :observer, :migration, :mailer
38
- self.class_type = :subclass
38
+ @class_type = :subclass
39
39
  # artifact subclass check
40
- self.superclass = SUPERCLASS_MAP[artifact_type]
40
+ @superclass = SUPERCLASS_MAP[artifact_type]
41
41
  when :model
42
42
  # check class == name
43
- self.class_type = :class
43
+ @class_type = :class
44
44
  end
45
45
  end
46
46
 
47
47
  def parse_name name
48
48
  if name.kind_of? Hash
49
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
50
+ @folder = view_options[:folder]
51
+ @action = view_options[:action]
52
+ @view_ext = view_options[:view_ext]
53
+ @artifact_type = :view
54
54
  return nil
55
55
  end
56
- self.artifact_name = name.to_s.downcase
57
- self.name = name.to_s.camelize
56
+ @artifact_name = name.to_s.downcase
57
+ @name = name.to_s.camelize
58
58
  end
59
59
 
60
60
  def find_artifact
@@ -77,7 +77,7 @@ module Artifact::Matcher
77
77
  end
78
78
  end
79
79
  if !artifact_found
80
- self.artifact_found = '[unknown]'
80
+ @artifact_found = '[unknown]'
81
81
  return nil
82
82
  end
83
83
 
@@ -1,6 +1,8 @@
1
1
  module RSpec::RailsApp::Directory
2
2
  module Matchers
3
3
  class HaveArtifactDirs
4
+ extend Rails3::Assist::UseMacro
5
+ use_helper :directory
4
6
 
5
7
  attr_accessor :artifact_type, :dir, :dir_name, :dirs
6
8
 
@@ -1,6 +1,8 @@
1
1
  module RSpec::RailsApp::Directory
2
2
  module Matchers
3
3
  class HaveRailsDir
4
+ extend Rails3::Assist::UseMacro
5
+ use_helper :directory
4
6
 
5
7
  attr_accessor :dir, :type
6
8
 
@@ -26,15 +28,7 @@ module RSpec::RailsApp::Directory
26
28
  HaveRailsDir.new(type)
27
29
  end
28
30
 
29
- ::Rails3::Assist::Directory::Root.root_directories.each do |name|
30
- class_eval %{
31
- def have_#{name}_dir
32
- have_rails_dir :#{name}
33
- end
34
- }
35
- end
36
-
37
- ::Rails3::Assist::Directory::App.app_directories.each do |name|
31
+ (Rails3::Assist.artifacts + Rails3::Assist.specials(:all) + Rails3::Assist::Directory::Root.root_directories).each do |name|
38
32
  class_eval %{
39
33
  def have_#{name}_dir
40
34
  have_rails_dir :#{name}
@@ -1,7 +1,9 @@
1
1
  module RSpec::RailsApp::Directory
2
2
  module Matchers
3
3
  class HaveRailsDirs
4
-
4
+ extend Rails3::Assist::UseMacro
5
+ use_helper :directory
6
+
5
7
  attr_accessor :dir, :dir_name, :dirs
6
8
 
7
9
  def initialize *dirs
@@ -4,6 +4,7 @@ module RSpec::RailsApp::File
4
4
  module Matchers
5
5
  class HaveRailsFile
6
6
  include ::Rails3::Assist::Artifact
7
+ include ::Rails3::Assist::File
7
8
  include RailsFile::Matcher::Helper
8
9
 
9
10
  def initialize(name, type = nil)
@@ -17,8 +18,8 @@ module RSpec::RailsApp::File
17
18
  end
18
19
  end
19
20
 
20
- def have_rails_file(type = nil)
21
- HaveRailsFile.new(type)
21
+ def have_rails_file(name, type=nil)
22
+ HaveRailsFile.new(name, type)
22
23
  end
23
24
 
24
25
  [:initializer, :db, :migration, :locale, :javascript, :stylesheet].each do |name|
@@ -4,6 +4,7 @@ module RSpec::RailsApp::File
4
4
  module Matchers
5
5
  class HaveRailsFiles
6
6
  include ::Rails3::Assist::Artifact
7
+ include ::Rails3::Assist::File
7
8
  include RailsFile::Matcher::Helper
8
9
 
9
10
  attr_reader :names
@@ -14,8 +15,10 @@ module RSpec::RailsApp::File
14
15
  end
15
16
 
16
17
  def matches?(obj, &block)
18
+ puts "type: #{type}"
17
19
  names.to_strings.each do |name|
18
20
  @name = name
21
+ puts "name: #{name}"
19
22
  @file = send(:"#{type}_file", name)
20
23
  return false if !File.file?(file)
21
24
  end
@@ -6,19 +6,21 @@ module RSpec::RailsApp::Content
6
6
  class HaveAppConfig
7
7
  extend Rails3::Assist::UseMacro
8
8
  use_helpers :file
9
+
10
+ include Rails3::Assist::File::Special
11
+ include Rails3::Assist::File::Application
9
12
 
10
13
  attr_reader :left_side, :right_side, :operator
11
14
 
12
- def initialize statement_hash
13
- @left_side, @right_side = *statement.first
14
- @operator = statement.last[:op] || '='
15
+ def initialize args
16
+ @left_side, @right_side = *args.first
17
+ @operator = last_arg_value({:op => '='}, args)
15
18
  end
16
19
 
17
20
  # TODO: relative to root_path ?
18
21
  def matches?(root_path=nil)
19
22
  content = read_application_file
20
- return nil if content.empty?
21
-
23
+ return nil if content.empty?
22
24
  ls, rs, op = escape_all(left_side, right_side, operator)
23
25
  (content =~ /config.#{ls}\s*#{op}\s*#{rs}/)
24
26
  end
@@ -8,6 +8,8 @@ module RSpec::RailsApp::Content
8
8
  class HaveGem
9
9
  extend Rails3::Assist::UseMacro
10
10
  use_helpers :file
11
+
12
+ include Rails3::Assist::File::Special
11
13
 
12
14
  attr_reader :name, :version, :options
13
15
 
@@ -26,7 +28,7 @@ module RSpec::RailsApp::Content
26
28
 
27
29
  # TODO: relative to root_path ?
28
30
  def matches?(root_path=nil)
29
- content = read_gemfile
31
+ content = read_gem_file
30
32
  return nil if content.empty?
31
33
  (content =~ /gem\s+#{name_expr}#{version_expr}/)
32
34
  end
@@ -9,6 +9,8 @@ module RSpec::RailsApp::Content
9
9
  class HaveGems
10
10
  extend Rails3::Assist::UseMacro
11
11
  use_helpers :file
12
+
13
+ include Rails3::Assist::File::Special
12
14
 
13
15
  attr_reader :names, :name
14
16
 
@@ -18,7 +20,7 @@ module RSpec::RailsApp::Content
18
20
 
19
21
  # TODO: relative to root_path ?
20
22
  def matches?(root_path=nil)
21
- content = read_gemfile
23
+ content = read_gem_file
22
24
  return nil if content.empty?
23
25
  names.each do |name|
24
26
  (content =~ /gem\s+#{name_expr(name)}/)
@@ -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.7"
8
+ s.version = "0.2.8"
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-14}
12
+ s.date = %q{2010-09-15}
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 = [
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  root_dir = Rails3::Assist::Directory.rails_root
4
4
 
5
5
  describe 'controller' do
6
- use_helper :controller
6
+ use_helpers :controller, :app
7
7
 
8
8
  before :each do
9
9
  create_empty_tmp :controller
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ root_dir = Rails3::Assist::Directory.rails_root
4
+
5
+ describe 'Rails matcher: have_rails_dir' do
6
+ use_helpers :directory, :app, :controller
7
+
8
+ before :each do
9
+ create_empty_tmp :controller
10
+ create_empty_tmp :locale
11
+ end
12
+
13
+ it "should not have an model dir" do
14
+ root_dir.should_not have_model_dir
15
+ end
16
+
17
+ it "should have a controller dir" do
18
+ root_dir.should have_controller_dir
19
+ end
20
+
21
+ it "should have a locale dir" do
22
+ root_dir.should have_locale_dir
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ root_dir = Rails3::Assist::Directory.rails_root
4
+
5
+ describe 'Rails matcher: have_rails_dirs' do
6
+ use_helpers :directory, :app
7
+
8
+ before :each do
9
+ create_empty_tmp :controller
10
+ create_empty_tmp :locale
11
+ end
12
+
13
+ it "should have a rails dirs :locale and :controller" do
14
+ root_dir.should have_rails_dirs :locale, :controller
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ root_dir = Rails3::Assist::Directory.rails_root
4
+
5
+ describe 'Rails matcher: have_rails_file' do
6
+ use_helpers :file, :controller
7
+
8
+ before :each do
9
+ create_controller :account do
10
+ %q{
11
+ def index
12
+ end
13
+ }
14
+ end
15
+
16
+ create_javascript :effects do
17
+ '# effects '
18
+ end
19
+ end
20
+
21
+ after :each do
22
+ remove_controller :account
23
+ remove_javascript :effects
24
+ end
25
+
26
+ it "should not have initializer :hello" do
27
+ root_dir.should_not have_initializer_file :hello
28
+ end
29
+
30
+ it "should have a controller :account" do
31
+ root_dir.should have_controller_file :account
32
+ end
33
+
34
+ it "should have a js :effects" do
35
+ root_dir.should have_javascript_file :effects
36
+ end
37
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ root_dir = Rails3::Assist::Directory.rails_root
4
+
5
+ describe 'Rails matcher: have_rails_files' do
6
+ use_helpers :files, :file, :controller, :view
7
+
8
+ before :each do
9
+ create_controller :account do
10
+ 'blip'
11
+ end
12
+
13
+ create_controller :person do
14
+ 'blap'
15
+ end
16
+
17
+ create_javascript :effects do
18
+ '# effects '
19
+ end
20
+
21
+ create_javascript :noise do
22
+ '# noise '
23
+ end
24
+
25
+ create_view :person, :edit do
26
+ '# edit person '
27
+ end
28
+
29
+ create_view :person, :new do
30
+ '# new person '
31
+ end
32
+ end
33
+
34
+ after :each do
35
+ # remove_controller :account
36
+ end
37
+
38
+ it "should have a controller :account, :person" do
39
+ root_dir.should have_controller_files :account, :person
40
+ end
41
+
42
+ it "should have a js :effects, :noise" do
43
+ root_dir.should have_javascript_files :effects, :noise
44
+ end
45
+
46
+ it "should not have a js files :effects, :sound" do
47
+ root_dir.should_not have_javascript_files :effects, :sound
48
+ end
49
+
50
+ it "should have a view :effects, :noise" do
51
+ root_dir.should have_view_files :edit, :new, :folder => :person
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ root_dir = Rails3::Assist::Directory.rails_root
4
+
5
+ describe 'Rails matcher: have_app_config' do
6
+ use_helpers :directory, :file, :app
7
+
8
+ before :each do
9
+ create_empty_tmp :config
10
+ Dir.chdir config_dir do
11
+ File.overwrite 'application.rb' do
12
+ %q{
13
+ config.root_dir = MY_ROOT
14
+ }
15
+ end
16
+ end
17
+ end
18
+
19
+ it "should not have initializer :hello" do
20
+ root_dir.should have_app_config :root_dir => 'MY_ROOT'
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ root = Rails3::Assist::Directory.rails_root
4
+
5
+ describe 'Rails matcher: have_gem' do
6
+ use_helpers :directory, :file
7
+
8
+ before :each do
9
+ puts "root: #{root_dir}"
10
+ Dir.chdir root_dir do
11
+ File.overwrite 'Gemfile' do
12
+ %q{
13
+ gem "cancan"
14
+ gem "devise", '1.1'
15
+ }
16
+ end
17
+ end
18
+ end
19
+
20
+ it "should have gem 'cancan'" do
21
+ root.should have_gem 'cancan'
22
+ end
23
+
24
+ it "should have gem 'devise' version 1.1" do
25
+ root.should have_gem 'cancan', '1.1'
26
+ end
27
+
28
+ it "should not have gem 'devise' version 1" do
29
+ root.should have_gem 'devise', '1'
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ root = Rails3::Assist::Directory.rails_root
4
+
5
+ describe 'Rails matcher: have_gems' do
6
+ use_helpers :directory, :file
7
+
8
+ before :each do
9
+ Dir.chdir root_dir do
10
+ File.overwrite 'Gemfile' do
11
+ %q{
12
+ gem "cancan"
13
+ gem "devise", '1.1'
14
+ gem "roles"
15
+ }
16
+ end
17
+ end
18
+ end
19
+
20
+ it "should have gems 'cancan', 'devise', 'roles'" do
21
+ root.should have_gems 'cancan', 'devise', 'roles'
22
+ end
23
+
24
+ it "should not have gems 'cancan', 'devise', 'roles_are_us'" do
25
+ root.should have_gems 'cancan', 'devise', 'roles_are_us'
26
+ end
27
+ end
@@ -8,8 +8,7 @@ RSpec.configure do |config|
8
8
 
9
9
  config.after do
10
10
  remove_temp_dir 'tmp_rails'
11
- end
12
-
11
+ end
13
12
  end
14
13
 
15
14
  def project_dir
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 7
9
- version: 0.2.7
8
+ - 8
9
+ version: 0.2.8
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-14 00:00:00 +02:00
17
+ date: 2010-09-15 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency