combustion 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,3 +1,8 @@
1
+ 0.2.0 - August 30th 2011
2
+ * Documentation.
3
+ * Allow developers to choose which Rails modules they wish to be loaded.
4
+ * Load Rails routes and Capybara helpers into RSpec examples when appropriate.
5
+
1
6
  0.1.1 - August 24th 2011
2
7
  * Support assets properly by loading ActionView and Sprockets railties.
3
8
 
@@ -1,7 +1,128 @@
1
1
  h1. Combustion
2
2
 
3
- More information/documentation coming soon.
3
+ Combustion is a library to help you test your Rails Engines in a simple and effective manner, instead of creating a full Rails application in your spec or test folder.
4
+
5
+ It allows you to write your specs within the context of your engine, using only the parts of a Rails app you need.
6
+
7
+ h2. Usage
8
+
9
+ Get the gem into either your gemspec or your Gemfile, depending on how you manage your engine's dependencies:
10
+
11
+ <pre><code># gemspec
12
+ gem.add_development_dependency 'combustion', '~> 0.2.0'
13
+ # Gemfile
14
+ gem 'combustion', '~> 0.2.0`, :group => :development</code></pre>
15
+
16
+ In your @spec_helper.rb@, get Combustion to set itself up - which has to happen before you introduce @rspec/rails@ and - if being used - @capybara/rspec@. Here's an example within context:
17
+
18
+ <pre><code>require 'rubygems'
19
+ require 'bundler'
20
+
21
+ Bundler.require :default, :development
22
+
23
+ Combustion.initialize!
24
+
25
+ require 'rspec/rails'
26
+ require 'capybara/rspec'
27
+
28
+ RSpec.configure do |config|
29
+ config.use_transactional_fixtures = true
30
+ end</code></pre>
31
+
32
+ What Combustion is doing is setting up a Rails application at @spec/internal@ - but you only need to add the files within that directory that you're going to use. Read on for some detail about what that involves.
33
+
34
+ h3. Configuring which Rails modules should be loaded.
35
+
36
+ By default, Combustion assumes you want the full Rails stack. You can customise this though - just pass in what you'd like loaded to the @Combustion.initialize!@ call:
37
+
38
+ <pre><code>Combustion.initialize! :active_record, :action_controller,
39
+ :action_view, :sprockets</code></pre>
40
+
41
+ ActiveSupport is always loaded, as it's an integral part of Rails.
42
+
43
+ h3. Using Models and ActiveRecord
44
+
45
+ If you're using ActiveRecord, then there's two critical files within your internal Rails app at @spec/internal@ that you'll need to create:
46
+
47
+ * config/database.yml
48
+ * db/schema.rb
49
+
50
+ Both follow the same structure as in any normal Rails application - and the schema file lets you avoid migrations, as it gets run whenever the test suite starts. Here's a quick sample (note that tables are overwritten if they already exist - this is necessary):
51
+
52
+ <pre><code>ActiveRecord::Schema.define do
53
+ create_table(:pages, :force => true) do |t|
54
+ t.string :name
55
+ t.text :content
56
+ t.timestamps
57
+ end
58
+ end</code></pre>
59
+
60
+ Any models that aren't provided by your engine should be located at @spec/internal/app/models@.
61
+
62
+ h3. Using ActionController and ActionView
63
+
64
+ You'll only need to add controllers and views to your internal Rails app for whatever you're testing that your engine doesn't provide - this may be nothing at all, so perhaps you don't even need @spec/internal/app/views@ or @spec/internal/app/controllers@ directories.
65
+
66
+ However, if you're doing any testing of your engine's controllers or views, then you're going to need routes set up for them - so create a standard routes file at @spec/internal/config/routes.rb@:
67
+
68
+ <pre><code>Rails.application.routes.draw do
69
+ resources :pages
70
+ end</code></pre>
71
+
72
+ Just like in a standard Rails app, if you have a mounted engine, then its routes are accessible through whatever it has been loaded as.
73
+
74
+ h3. Environment and Logging
75
+
76
+ Your tests will execute within the test environment for the internal Rails app - and so logs are available at @spec/internal/log/test.log@. You should probably create that log directory so Rails doesn't complain.
77
+
78
+ h3. Rack it up
79
+
80
+ Once you've got this set up, you can fire up your test environment quite easily with Rack - here's an example @config.ru@ file that could live in the root of your engine folder:
81
+
82
+ <pre><code>require 'rubygems'
83
+ require 'bundler'
84
+
85
+ Bundler.require :default, :development
86
+
87
+ Combustion.initialize!
88
+ run Combustion::Application</code></pre>
89
+
90
+ h3. Get your test on!
91
+
92
+ Now you're good to go - you can write specs within your engine's spec directory just like you were testing a full Rails application - models in @spec/models@, controllers in @spec/controllers@. If you bring Capybara into the mix, then the standard helpers helpers from that will be loaded as well.
93
+
94
+ <pre><code>require 'spec_helper'
95
+
96
+ describe Page do
97
+ describe '#valid' do
98
+ it 'requires a name' do
99
+ # This is just an example. Go write your own tests!
100
+ end
101
+ end
102
+ end</code></pre>
103
+
104
+ h2. Compatibility
105
+
106
+ Developed for Rails 3.1 and Ruby 1.9. It should work on any other Ruby, and possibly Rails 3.0, but will not work neatly with earlier versions of Rails.
107
+
108
+ h2. Limitations and Known Issues
109
+
110
+ Combustion is currently written with the expectation it'll be used with RSpec. I'd love to make this more flexible - if you want to give it a shot before I get around to it, patches are very much welcome.
111
+
112
+ I'm also keen to have a generator that adds the standard set of files and folders (@config/database.yml@, @config/routes.rb@, @db/schema.rb@, @log@) into @spec/internal@, just to make it even easier to get going. Again, patches are welcome for this, but I'll likely get to it pretty soon.
113
+
114
+ I've not tried using this with Cucumber, but it should work in theory without too much hassle. Let me know if I'm wrong!
115
+
116
+ h2. Contributing
117
+
118
+ Contributions are very much welcome - but keep in mind the following:
119
+
120
+ * Keep patches in a separate branch
121
+ * Don't mess with the version or history file. I'll take care of that when the patch is merged in.
122
+ * Write tests - look at the existing tests (particularly in @spec/acceptance@)
123
+
124
+ There are no tests - partly because Combustion was extracted out from the tests of HyperTiny's Dobro, and partly because there's not much code. Still, if you can find a clean way of testing this, that'd be fantastic.
4
125
 
5
126
  h2. Credits
6
127
 
7
- Combustion is developed and maintained by Pat Allan, and is released under the open MIT Licence.
128
+ Copyright (c) 2011, Combustion is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to HyperTiny for encouraging its development.
@@ -1,17 +1,27 @@
1
1
  require 'rails'
2
2
  require 'active_support/dependencies'
3
- require 'active_record/railtie'
4
- require 'action_controller/railtie'
5
- require 'action_view/railtie'
6
- require 'sprockets/railtie'
7
3
 
8
4
  module Combustion
9
- def self.initialize!
5
+ Modules = %w( active_record action_controller action_view action_mailer
6
+ sprockets )
7
+
8
+ def self.initialize!(*modules)
9
+ modules = Modules if modules.empty? || modules == [:all]
10
+ modules.each { |mod| require "#{mod}/railtie" }
11
+
12
+ Combustion::Application.configure_for_combustion
10
13
  Combustion::Application.initialize!
11
14
 
12
15
  silence_stream(STDOUT) do
13
16
  load "#{Rails.root}/db/schema.rb"
14
17
  end
18
+
19
+ RSpec.configure do |config|
20
+ config.include(Capybara) if defined?(Capybara)
21
+
22
+ config.include(Combustion::Application.routes.url_helpers)
23
+ config.include(Combustion::Application.routes.mounted_helpers)
24
+ end if defined?(RSpec) && RSpec.respond_to?(:configure)
15
25
  end
16
26
  end
17
27
 
@@ -12,15 +12,23 @@ class Combustion::Application < Rails::Application
12
12
  # ActiveSupport Settings
13
13
  config.active_support.deprecation = :stderr
14
14
 
15
- # Action Controller and Action Dispatch
16
- config.action_dispatch.show_exceptions = false
17
- config.action_controller.perform_caching = false
18
- config.action_controller.allow_forgery_protection = false
15
+ # Some settings we're not sure if we want, so let's not load them by default.
16
+ # Instead, wait for this method to be invoked (to get around load-order
17
+ # complications).
18
+ def self.configure_for_combustion
19
+ if defined?(ActionController) && defined?(ActionController::Engine)
20
+ config.action_dispatch.show_exceptions = false
21
+ config.action_controller.perform_caching = false
22
+ config.action_controller.allow_forgery_protection = false
23
+ end
19
24
 
20
- # Action Mailer Settings
21
- # config.action_mailer.delivery_method = :test
22
- # config.action_mailer.default_url_options = {:host => 'www.example.com'}
25
+ if defined?(ActionMailer) && defined?(ActionMailer::Engine)
26
+ config.action_mailer.delivery_method = :test
27
+ config.action_mailer.default_url_options = {:host => 'www.example.com'}
28
+ end
23
29
 
24
- # Asset Settings
25
- config.assets.enabled = true
30
+ if defined?(Sprockets)
31
+ config.assets.enabled = true
32
+ end
33
+ end
26
34
  end
@@ -1,3 +1,3 @@
1
1
  module Combustion
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combustion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-24 00:00:00.000000000 Z
12
+ date: 2011-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2156734700 !ruby/object:Gem::Requirement
16
+ requirement: &2152591540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 3.1.0.rc5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156734700
24
+ version_requirements: *2152591540
25
25
  description: Test your Rails Engines without needing a full Rails app
26
26
  email:
27
27
  - pat@freelancing-gods.com