rails-sandbox-assets 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -8,19 +8,66 @@ Add this line to your application's Gemfile:
|
|
8
8
|
|
9
9
|
gem 'rails-sandbox-assets'
|
10
10
|
|
11
|
+
Or if you prefer to use the master branch:
|
12
|
+
|
13
|
+
gem 'rails-sandbox-assets', git: 'git://github.com/rosenfeld/rails-sandbox-assets' # or:
|
14
|
+
gem 'rails-sandbox-assets', github: 'rosenfeld/rails-sandbox-assets' # Bundler-pre syntax
|
15
|
+
|
11
16
|
And then execute:
|
12
17
|
|
13
18
|
$ bundle
|
14
19
|
|
15
20
|
## Usage
|
16
21
|
|
22
|
+
Place your tests under _test/javascripts/\*\_test.js_ or _specs/javascripts/\*\_spec.js.coffee_.
|
23
|
+
Use JavaScript or CoffeeScript.
|
24
|
+
|
25
|
+
You can add your test assets to _test/assets/javascripts_, _test/assets/stylesheets_,.
|
26
|
+
_specs/assets/javascripts_ and _specs/assets/stylesheets_.
|
27
|
+
|
17
28
|
$ rake sandbox_assets:serve
|
18
29
|
|
19
30
|
Follow the instructions in http://localhost:5000 for how to override the void bundled test-runner.
|
20
31
|
|
32
|
+
You can run a subset of your tests by specifying a path like _http://localhost:5000/products_.
|
33
|
+
|
34
|
+
This will only run your tests which path starts with _test/javascripts/products_, for example.
|
35
|
+
|
21
36
|
## Settings
|
22
37
|
|
23
|
-
|
38
|
+
You can change your settings directly from config/application.rb, if you want to:
|
39
|
+
|
40
|
+
config.sandbox_assets.template = 'spec_runner/runner'
|
41
|
+
|
42
|
+
By default this setting is nil, which will follow the Rails convention and use
|
43
|
+
_app/views/sandbox_assets/test_runner/index.html.erb_. You could actually use HAML if you prefer.
|
44
|
+
|
45
|
+
Just create such file in your application to override the default one. With the option in the
|
46
|
+
example above, you should create your view in _app/views/spec_runner/runner.html.erb_.
|
47
|
+
|
48
|
+
Or you can create a separate initializer if you prefer:
|
49
|
+
|
50
|
+
# config/initializers/setup_sandbox_assets.rb
|
51
|
+
SandboxAssets::Engine.config.sandbox_assets.tap do |c|
|
52
|
+
c.template = 'test_runner/index' # set the runner template path
|
53
|
+
c.disable_template_param = true
|
54
|
+
end
|
55
|
+
|
56
|
+
Default settings:
|
57
|
+
|
58
|
+
c.port = 5000
|
59
|
+
# By default, sandbox_assets will look for your tests in test/javascripts and specs/javascripts
|
60
|
+
c.tests_roots = %w(test/javascripts specs/javascripts)
|
61
|
+
# Add to Rails assets path. Besides your tests/specs, any assets in those paths will be served
|
62
|
+
# by the asset pipeline:
|
63
|
+
c.assets_paths = c.tests_roots +
|
64
|
+
%w(test/assets/javascripts test/assets/stylesheets
|
65
|
+
specs/assets/javascripts specs/assets/stylesheets)
|
66
|
+
# Pattern to find your tests or specs inside the tests_roots directories:
|
67
|
+
c.tests_patterns = %w(**/*_{test,spec}.{js,coffee}*)
|
68
|
+
# By default, you can override which template to use in the params, like:
|
69
|
+
# http://localhost:5000/?template=spec_runner/runner
|
70
|
+
c.disable_template_param = false
|
24
71
|
|
25
72
|
## Examples
|
26
73
|
|
@@ -2,9 +2,36 @@ require "sandbox_assets/test_asset"
|
|
2
2
|
|
3
3
|
module SandboxAssets
|
4
4
|
class BaseController < ActionController::Base
|
5
|
-
|
5
|
+
before_filter :find_tests
|
6
|
+
before_filter :extract_template_from_params
|
7
|
+
before_filter :render_template
|
8
|
+
|
9
|
+
# additional before_filters can use this
|
10
|
+
def template=(template)
|
11
|
+
@template = template
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def find_tests
|
6
17
|
@tests = TestAsset.find_tests(params)
|
7
18
|
end
|
19
|
+
|
20
|
+
def extract_template_from_params
|
21
|
+
@template ||= params[:template] unless cfg.disable_template_param
|
22
|
+
end
|
23
|
+
|
24
|
+
def render_template
|
25
|
+
render @template if template
|
26
|
+
end
|
27
|
+
|
28
|
+
def template
|
29
|
+
@template ||= cfg.template
|
30
|
+
end
|
31
|
+
|
32
|
+
def cfg
|
33
|
+
@cfg ||= Engine.config.sandbox_assets
|
34
|
+
end
|
8
35
|
end
|
9
36
|
end
|
10
37
|
|
@@ -1,14 +1,17 @@
|
|
1
1
|
module SandboxAssets
|
2
2
|
class Settings
|
3
3
|
attr_reader :options
|
4
|
-
attr_accessor :tests_roots, :assets_paths, :tests_patterns, :port
|
4
|
+
attr_accessor :tests_roots, :assets_paths, :tests_patterns, :port,
|
5
|
+
:template, :disable_template_param
|
5
6
|
|
6
7
|
def initialize
|
7
8
|
@tests_roots = %w(test/javascripts specs/javascripts)
|
8
|
-
@assets_paths = @tests_roots +
|
9
|
-
%w(test/assets/javascripts
|
9
|
+
@assets_paths = @tests_roots +
|
10
|
+
%w(test/assets/javascripts test/assets/stylesheets
|
11
|
+
specs/assets/javascripts specs/assets/stylesheets)
|
10
12
|
@tests_patterns = %w(**/*_{test,spec}.{js,coffee}*)
|
11
13
|
@port = 5000
|
14
|
+
@disable_template_param = false
|
12
15
|
@options = {}
|
13
16
|
end
|
14
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-sandbox-assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -65,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
65
|
version: '0'
|
66
66
|
segments:
|
67
67
|
- 0
|
68
|
-
hash: -
|
68
|
+
hash: -3281811653558395831
|
69
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
70
|
none: false
|
71
71
|
requirements:
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
segments:
|
76
76
|
- 0
|
77
|
-
hash: -
|
77
|
+
hash: -3281811653558395831
|
78
78
|
requirements: []
|
79
79
|
rubyforge_project:
|
80
80
|
rubygems_version: 1.8.21
|