jspec-jquery-sandbox 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2010 Yann Lugrin <yann.lugrin@sans-savoir.net>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,71 @@
1
+ = jSpec Sandbox - a window sandbox for jQuery applications testing
2
+
3
+ * jSpec Sandbox website: https://github.com/yannlugrin/jspec-sandbox
4
+ * jSpec Sandbox on github: https://github.com/yannlugrin/jspec-sandbox
5
+ * jSpec website: http://jspec.info
6
+ * jQuery website: http://jquery.com
7
+
8
+ == Documentation
9
+
10
+ After sandbox is installed, all jQuery call is redirected in sandbox context
11
+ (an iframe) and be reset after each test. You can use `_jQuery()' or `_$()' to
12
+ call jQuery in jspec context.
13
+
14
+ Utility `sandbox()' return a jQuery object from sandbox:
15
+
16
+ * sandbox() => return sandbox body
17
+ * sandbox('<p></p>') => append to sandboy body an `p' element and return it
18
+ * sandbox('my-fixture') => append a sandbox body the content of fixture file and return it (child of body element)
19
+
20
+ === install with jspec command tool
21
+
22
+ First install [gem](http://gemcutter.org/) then execute:
23
+
24
+ $ sudo gem install jspec-jquery-sandbox
25
+
26
+ At which point go into your projext folder and execute:
27
+
28
+ $ echo "require 'jspec/jquery/sandbox/installable'" > spec/commands/jquery_sandbox_command.rb
29
+ $ jspec install jquerysandbox
30
+
31
+ This command add `jspec.jquery.sandbox.js' and `jspec.jquery.sandbox.html' files
32
+ into your `spec/support' folder.
33
+
34
+ After this step edit `dom.html' file to require sanbox lib after jquery and
35
+ add iframe with sandbox source.
36
+
37
+ ...
38
+ <script src="./lib/jquery.js"></script>
39
+ <script src="./support/jspec.jquery.sandbox.js"></script>
40
+ <script>
41
+ function runSuites() {
42
+ ...
43
+ <iframe id="sandbox" name="sandbox" src="./support/jspec.jquery.sandbox.html" style="display:none"></iframe>
44
+ </body>
45
+ ...
46
+
47
+ === install manually
48
+
49
+ Just copy `jspec.jquery.sandbox.js' and `jspec.jquery.sandbox.html' files
50
+ lib folder to your project `spec/support' folder.
51
+
52
+ After this step edit `dom.html' file to require sanbox lib after jquery and
53
+ add iframe with sandbox source.
54
+
55
+ ...
56
+ <script src="./lib/jquery.js"></script>
57
+ <script src="./support/jspec.jquery.sandbox.js"></script>
58
+ <script>
59
+ function runSuites() {
60
+ ...
61
+ <iframe id="sandbox" name="sandbox" src="./support/jspec.jquery.sandbox.html" style="display:none"></iframe>
62
+ </body>
63
+ ...
64
+
65
+ == Copyright and Licenses
66
+
67
+ Licensed under the MIT license (read LICENSE file). This library depends on
68
+ jSpec, also licensed under the MIT licence.
69
+
70
+ * jSpec Sandbox - Copyright (c) 2010 Yann Lugrin
71
+ * jSpec - Copyright (c) 2010 TJ Holowaychuk
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = 'jspec-jquery-sandbox'
8
+ gem.summary = %Q{a window sandbox for jQuery application testing with jSpec}
9
+ gem.email = 'yann.lugrin@sans-savoir.net'
10
+ gem.homepage = 'http://github.com/yannlugrin/jspec-jquery-sandbox'
11
+ gem.authors = ['Yann Lugrin']
12
+ gem.files = FileList["[A-Z]*", "{lib,src}/**/*"]
13
+ gem.require_paths = ['src']
14
+ gem.add_dependency 'jspec'
15
+ gem.add_development_dependency 'rspec', '>= 2.0.0.beta'
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'rspec/core/rake_task'
24
+ RSpec::Core::RakeTask.new(:spec)
25
+ RSpec::Core::RakeTask.new(:rdoc) do |spec|
26
+ spec.rcov = true
27
+ end
28
+
29
+ task :spec => :check_dependencies
30
+
31
+ task :default => :spec
32
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE HTML>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title></title>
6
+ </head>
7
+ <body class="sandbox">
8
+
9
+ </body>
10
+ </html>
@@ -0,0 +1,83 @@
1
+
2
+ // jQuery is required
3
+ JSpec.requires('jQuery', 'when using jspec.jquery.sandbox.js');
4
+
5
+ /*
6
+ * jQuery Sandbox
7
+ */
8
+ (function(JSpec, jQuery, undefined) {
9
+
10
+ var $ = jQuery;
11
+
12
+ // jQuery with jSpec context
13
+ var jQueryInit = jQuery.fn.init;
14
+
15
+ var _$ = _jQuery = function(selector, context) {
16
+ jQuery.fn.init = jQueryInit;
17
+ var result = jQuery(selector, context);
18
+ jQuery.fn.init = jQuerySandboxInit;
19
+
20
+ return result;
21
+ }
22
+
23
+ // jQuery with sandbox context (default)
24
+ var jQuerySandboxInit = function (selector, context) {
25
+ if (_$('iframe[name=sandbox]').length === 0) {
26
+ throw 'need a iframe named `sandbox\' when using jspec.jquery.sandbox.js';
27
+ }
28
+
29
+ context = (frames['sandbox'] && frames['sandbox'].document) || context;
30
+ return jQueryInit.apply(this, [selector, context]);
31
+ }
32
+ jQuerySandboxInit.prototype = jQueryInit.prototype;
33
+
34
+ jQuery.fn.init = jQuerySandboxInit;
35
+
36
+ /*
37
+ * Module
38
+ */
39
+ JSpec.include({
40
+ name: 'jQuerySandbox',
41
+
42
+ /*
43
+ * Initialization
44
+ */
45
+
46
+ init: function() {
47
+ },
48
+
49
+ /*
50
+ * Utilities
51
+ */
52
+
53
+ utilities: {
54
+ // sandbox return a jQuery object for box element of sandbox
55
+ // or for passed element (this element can be a html string or
56
+ // fixture name.
57
+ sandbox: function(content) {
58
+ if (content && content.match(/^[ ]*<.+>[ ]*$/mi)) {
59
+ content = $(content).appendTo('body');
60
+ } else if (content) {
61
+ content = $(this.fixture(content)).appendTo('body');
62
+ }
63
+
64
+ return content || $('body');
65
+ },
66
+
67
+ // alias to jQuery with jspec context
68
+ _$: _jQuery,
69
+ _jQuery: _jQuery,
70
+ },
71
+
72
+ /*
73
+ * Hooks
74
+ */
75
+
76
+ // clear sandbox
77
+ afterSpec: function(spec) {
78
+ $('body').html('');
79
+ },
80
+
81
+ });
82
+
83
+ })(JSpec, jQuery);
@@ -0,0 +1,19 @@
1
+
2
+ # uncomment and call with `$ jspec example `
3
+
4
+ # command :example do |c|
5
+ # c.syntax = 'jspec example [options]'
6
+ # c.description = 'Just an example command'
7
+ # c.option '-f', '--foo string', 'Does some foo with <string>'
8
+ # c.option '-b', '--bar [string]', 'Does some bar with [string]'
9
+ # c.example 'Do some foo', 'jspec example --foo bar'
10
+ # c.example 'Do some bar', 'jspec example --bar'
11
+ # c.when_called do |args, options|
12
+ # p args
13
+ # p options.__hash__
14
+ # # options.foo
15
+ # # options.bar
16
+ # # options.__hash__[:foo]
17
+ # # options.__hash__[:bar]
18
+ # end
19
+ # end
@@ -0,0 +1 @@
1
+ require 'jspec/jquery/sandbox/installable'
@@ -0,0 +1,38 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ include FileUtils
3
+
4
+ describe 'jspec' do
5
+ describe 'install' do
6
+ before :each do
7
+ @dest = File.expand_path('../test', __FILE__)
8
+ mkdir @dest
9
+ jspec(:init, @dest)
10
+ File.open(File.join(@dest, 'spec', 'commands', 'jquery_sandbox_command.rb'), 'w+') do |file|
11
+ file.write "require '#{File.expand_path('../../../src/jspec/jquery/sandbox/installable', __FILE__)
12
+ }'"
13
+ end
14
+ end
15
+
16
+ after :each do
17
+ rm_rf @dest
18
+ end
19
+
20
+ describe 'jquery sandbox' do
21
+ it "should install to spec/support/jspec.jquery.sandbox.js by default" do
22
+ Dir.chdir @dest do
23
+ jspec(:install, 'jquerysandbox')
24
+ File.exists?('spec/support/jspec.jquery.sandbox.js').should be_true
25
+ File.exists?('spec/support/jspec.jquery.sandbox.html').should be_true
26
+ end
27
+ end
28
+
29
+ it 'should install to the destination passed' do
30
+ jspec(:install, 'jquerysandbox', "#{@dest}/spec")
31
+ File.exists?("#{@dest}/spec/jspec.jquery.sandbox.js").should be_true
32
+ File.exists?("#{@dest}/spec/jspec.jquery.sandbox.html").should be_true
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'rspec/autorun'
4
+ require 'fileutils'
5
+
6
+ def jspec *args
7
+ `jspec #{args.join(' ')}`
8
+ end
9
+
@@ -0,0 +1,42 @@
1
+ require 'open-uri'
2
+
3
+ module JSpec
4
+ class Installable
5
+ class Jquerysandbox < self
6
+
7
+ def before
8
+ warn 'jQuery Sandbox does not yet support --release' if options[:release]
9
+ end
10
+
11
+ def lib_source
12
+ File.expand_path('../../../../../lib/jspec.jquery.sandbox.js', __FILE__)
13
+ end
14
+
15
+ def sandbox_source
16
+ File.expand_path('../../../../../lib/jspec.jquery.sandbox.html', __FILE__)
17
+ end
18
+
19
+ def lib_dest
20
+ options[:to] + '/jspec.jquery.sandbox.js'
21
+ end
22
+
23
+ def sandbox_dest
24
+ options[:to] + '/jspec.jquery.sandbox.html'
25
+ end
26
+
27
+ def install
28
+ File.open(lib_dest, 'w+') do |file|
29
+ file.write open(lib_source).read
30
+ end
31
+ File.open(sandbox_dest, 'w+') do |file|
32
+ file.write open(sandbox_source).read
33
+ end
34
+ end
35
+
36
+ def install_message
37
+ "jQuery Sandbox installed to #{lib_dest} and #{sandbox_dest}"
38
+ end
39
+
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jspec-jquery-sandbox
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - Yann Lugrin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-30 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: jspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 31098209
44
+ segments:
45
+ - 2
46
+ - 0
47
+ - 0
48
+ - beta
49
+ version: 2.0.0.beta
50
+ type: :development
51
+ version_requirements: *id002
52
+ description:
53
+ email: yann.lugrin@sans-savoir.net
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files:
59
+ - LICENSE
60
+ - README.rdoc
61
+ files:
62
+ - LICENSE
63
+ - README.rdoc
64
+ - Rakefile
65
+ - VERSION
66
+ - lib/jspec.jquery.sandbox.html
67
+ - lib/jspec.jquery.sandbox.js
68
+ - src/jspec/jquery/sandbox/installable.rb
69
+ - spec/ruby/spec_helper.rb
70
+ - spec/ruby/installable_spec.rb
71
+ - spec/commands/jquery_sandbox_command.rb
72
+ - spec/commands/example_commands.rb
73
+ has_rdoc: true
74
+ homepage: http://github.com/yannlugrin/jspec-jquery-sandbox
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - src
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.7
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: a window sandbox for jQuery application testing with jSpec
107
+ test_files:
108
+ - spec/ruby/spec_helper.rb
109
+ - spec/ruby/installable_spec.rb
110
+ - spec/commands/jquery_sandbox_command.rb
111
+ - spec/commands/example_commands.rb