Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Basic specs for plugin loading

  • Loading branch information...
commit 576a6817a039d611c1ab9bcaafa68e0a84c707b3 1 parent f5d481c
Nicos Gollan authored May 11, 2011
4  .rspec
... ...
@@ -0,0 +1,4 @@
  1
+--color
  2
+--format progress
  3
+--format html
  4
+--out rspec_results.html
24  Rakefile
... ...
@@ -1,4 +1,5 @@
1 1
 require File.expand_path("../merb-core/lib/merb-core/version.rb", __FILE__)
  2
+require File.expand_path("../merb/lib/merb/stack_info.rb", __FILE__)
2 3
 
3 4
 require 'fileutils'
4 5
 
@@ -25,22 +26,7 @@ yard_local_options = [
25 26
   ['--no-yardopts']
26 27
 ]
27 28
 
28  
-merb_stack_gems = [
29  
-  { :name => 'merb-core',             :path => "#{ROOT}/merb-core",             :doc => :yard },
30  
-  { :name => 'merb-action-args',      :path => "#{ROOT}/merb-action-args",      :doc => :yard },
31  
-  { :name => 'merb-assets',           :path => "#{ROOT}/merb-assets",           :doc => :yard },
32  
-  { :name => 'merb-slices',           :path => "#{ROOT}/merb-slices",           :doc => :yard },
33  
-  { :name => 'merb-cache',            :path => "#{ROOT}/merb-cache",            :doc => :yard },
34  
-  { :name => 'merb-gen',              :path => "#{ROOT}/merb-gen",              :doc => :yard },
35  
-  { :name => 'merb-haml',             :path => "#{ROOT}/merb-haml",             :doc => :yard },
36  
-  { :name => 'merb-helpers',          :path => "#{ROOT}/merb-helpers",          :doc => :yard },
37  
-  { :name => 'merb-mailer',           :path => "#{ROOT}/merb-mailer",           :doc => :yard },
38  
-  { :name => 'merb-param-protection', :path => "#{ROOT}/merb-param-protection", :doc => :yard },
39  
-  { :name => 'merb-exceptions',       :path => "#{ROOT}/merb-exceptions",       :doc => :yard },
40  
-  { :name => 'merb-auth',             :path => "#{ROOT}/../merb-auth",          :doc => :rdoc },
41  
-  { :name => 'merb_datamapper',       :path => "#{ROOT}/../merb_datamapper",    :doc => :rdoc },
42  
-  { :name => 'merb',                  :path => "#{ROOT}/merb",                  :doc => :rdoc }
43  
-]
  29
+merb_stack_gems = Merb::STACK_GEMS
44 30
 
45 31
 def gem_command(command, *args)
46 32
   sh "#{RUBY} -S gem #{command} #{args.join(' ')}"
@@ -54,7 +40,7 @@ end
54 40
 desc "Install all merb stack gems"
55 41
 task :install do
56 42
   merb_stack_gems.each do |gem_info|
57  
-    Dir.chdir(gem_info[:path]) { rake_command "install" }
  43
+    Dir.chdir(File.join(ROOT, gem_info[:path])) { rake_command "install" }
58 44
   end
59 45
 end
60 46
 
@@ -68,7 +54,7 @@ end
68 54
 desc "Build all merb stack gems"
69 55
 task :build do
70 56
   merb_stack_gems.each do |gem_info|
71  
-    Dir.chdir(gem_info[:path]) { gem_command "build", "#{gem_info[:name]}.gemspec" }
  57
+    Dir.chdir(File.join(ROOT, gem_info[:path])) { gem_command "build", "#{gem_info[:name]}.gemspec" }
72 58
   end
73 59
 end
74 60
 
@@ -76,7 +62,7 @@ desc "Run specs for all merb stack gems"
76 62
 task :spec do
77 63
   # Omit the merb metagem, no specs there
78 64
   merb_stack_gems[0..-2].each do |gem_info|
79  
-    Dir.chdir(gem_info[:path]) { rake_command "spec" }
  65
+    Dir.chdir(File.join(ROOT, gem_info[:path])) { rake_command "spec" }
80 66
   end
81 67
 end
82 68
 
25  merb/lib/merb/stack_info.rb
... ...
@@ -0,0 +1,25 @@
  1
+module Merb
  2
+  # List of gems in the Merb stack.
  3
+  #
  4
+  # The `:path` entry is relative to a root in a common development
  5
+  # environment where all gems are residing under a common directory.
  6
+  #
  7
+  # @note Make sure that merb-core is always the first element.
  8
+  STACK_GEMS = [
  9
+    { :name => 'merb-core',             :path => "merb-core",             :doc => :yard, :repo => 'merb' },
  10
+    { :name => 'merb-action-args',      :path => "merb-action-args",      :doc => :yard, :repo => 'merb' },
  11
+    { :name => 'merb-assets',           :path => "merb-assets",           :doc => :yard, :repo => 'merb' },
  12
+    { :name => 'merb-slices',           :path => "merb-slices",           :doc => :yard, :repo => 'merb' },
  13
+    { :name => 'merb-cache',            :path => "merb-cache",            :doc => :yard, :repo => 'merb' },
  14
+    { :name => 'merb-gen',              :path => "merb-gen",              :doc => :yard, :repo => 'merb' },
  15
+    { :name => 'merb-haml',             :path => "merb-haml",             :doc => :yard, :repo => 'merb' },
  16
+    { :name => 'merb-helpers',          :path => "merb-helpers",          :doc => :yard, :repo => 'merb' },
  17
+    { :name => 'merb-mailer',           :path => "merb-mailer",           :doc => :yard, :repo => 'merb' },
  18
+    { :name => 'merb-param-protection', :path => "merb-param-protection", :doc => :yard, :repo => 'merb' },
  19
+    { :name => 'merb-exceptions',       :path => "merb-exceptions",       :doc => :yard, :repo => 'merb' },
  20
+    { :name => 'merb-auth',             :path => "../merb-auth",          :doc => :rdoc, :repo => 'merb-auth' },
  21
+    { :name => 'merb_datamapper',       :path => "../merb_datamapper",    :doc => :rdoc, :repo => 'merb_datamapper' },
  22
+    { :name => 'merb',                  :path => "merb",                  :doc => :rdoc, :repo => 'merb' }
  23
+  ]
  24
+end
  25
+
25  spec/plugins_spec.rb
... ...
@@ -0,0 +1,25 @@
  1
+require 'spec_helper'
  2
+
  3
+shared_examples_for "a loadable plugin" do |plugin_info|
  4
+  it "should be possible to load both a gem and its version.rb" do
  5
+    plugin = plugin_info[:path]
  6
+    lib_dir = plugin_path(plugin)
  7
+
  8
+    if File.directory?(lib_dir) && File.exist?(File.join(lib_dir, 'lib', plugin_info[:name], 'version.rb'))
  9
+      $LOAD_PATH.unshift(File.join(lib_dir, 'lib'))
  10
+    else
  11
+      pending "No plugin found or missing version.rb at #{lib_dir}"
  12
+    end
  13
+
  14
+    expect do
  15
+      require File.join(plugin_info[:name], 'version')
  16
+      require plugin_info[:name]
  17
+    end.to_not raise_error
  18
+  end
  19
+end
  20
+
  21
+Merb::STACK_GEMS.each do |gem_info|
  22
+  describe gem_info[:name] do
  23
+    it_should_behave_like "a loadable plugin", gem_info
  24
+  end
  25
+end
11  spec/spec_helper.rb
... ...
@@ -0,0 +1,11 @@
  1
+require "rubygems"
  2
+require 'rspec'
  3
+
  4
+require File.expand_path("../../merb/lib/merb/stack_info", __FILE__)
  5
+
  6
+RSpec.configure do |config|
  7
+  def plugin_path(relative_path, *elements)
  8
+    subpath = File.join(relative_path, *elements)
  9
+    File.expand_path(File.join('../../', subpath), __FILE__)
  10
+  end
  11
+end

0 notes on commit 576a681

Please sign in to comment.
Something went wrong with that request. Please try again.