js_fixtures 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +76 -0
- data/LICENSE.txt +20 -0
- data/README +23 -0
- data/README.rdoc +45 -0
- data/Rakefile +26 -0
- data/VERSION +1 -0
- data/js_fixtures.gemspec +62 -0
- data/lib/js_fixtures.rb +50 -0
- metadata +119 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
gem "rspec"
|
9
|
+
gem "rspec-rails"
|
10
|
+
gem 'jasmine'
|
11
|
+
|
12
|
+
group :development do
|
13
|
+
gem "bundler", "~> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.6.4"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionpack (3.0.7)
|
6
|
+
activemodel (= 3.0.7)
|
7
|
+
activesupport (= 3.0.7)
|
8
|
+
builder (~> 2.1.2)
|
9
|
+
erubis (~> 2.6.6)
|
10
|
+
i18n (~> 0.5.0)
|
11
|
+
rack (~> 1.2.1)
|
12
|
+
rack-mount (~> 0.6.14)
|
13
|
+
rack-test (~> 0.5.7)
|
14
|
+
tzinfo (~> 0.3.23)
|
15
|
+
activemodel (3.0.7)
|
16
|
+
activesupport (= 3.0.7)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
i18n (~> 0.5.0)
|
19
|
+
activesupport (3.0.7)
|
20
|
+
builder (2.1.2)
|
21
|
+
diff-lcs (1.1.2)
|
22
|
+
erubis (2.6.6)
|
23
|
+
abstract (>= 1.0.0)
|
24
|
+
git (1.2.5)
|
25
|
+
i18n (0.5.0)
|
26
|
+
jasmine (1.0.1.1)
|
27
|
+
json_pure (>= 1.4.3)
|
28
|
+
rack (>= 1.0.0)
|
29
|
+
rake (>= 0.8.7)
|
30
|
+
rspec (>= 1.1.5)
|
31
|
+
selenium-client (>= 1.2.17)
|
32
|
+
selenium-rc (>= 2.1.0)
|
33
|
+
jeweler (1.6.4)
|
34
|
+
bundler (~> 1.0)
|
35
|
+
git (>= 1.2.5)
|
36
|
+
rake
|
37
|
+
json_pure (1.5.3)
|
38
|
+
rack (1.2.3)
|
39
|
+
rack-mount (0.6.14)
|
40
|
+
rack (>= 1.0.0)
|
41
|
+
rack-test (0.5.7)
|
42
|
+
rack (>= 1.0)
|
43
|
+
railties (3.0.7)
|
44
|
+
actionpack (= 3.0.7)
|
45
|
+
activesupport (= 3.0.7)
|
46
|
+
rake (>= 0.8.7)
|
47
|
+
thor (~> 0.14.4)
|
48
|
+
rake (0.9.2)
|
49
|
+
rspec (2.6.0)
|
50
|
+
rspec-core (~> 2.6.0)
|
51
|
+
rspec-expectations (~> 2.6.0)
|
52
|
+
rspec-mocks (~> 2.6.0)
|
53
|
+
rspec-core (2.6.4)
|
54
|
+
rspec-expectations (2.6.0)
|
55
|
+
diff-lcs (~> 1.1.2)
|
56
|
+
rspec-mocks (2.6.0)
|
57
|
+
rspec-rails (2.6.1)
|
58
|
+
actionpack (~> 3.0)
|
59
|
+
activesupport (~> 3.0)
|
60
|
+
railties (~> 3.0)
|
61
|
+
rspec (~> 2.6.0)
|
62
|
+
selenium-client (1.2.18)
|
63
|
+
selenium-rc (2.2.4)
|
64
|
+
selenium-client (>= 1.2.18)
|
65
|
+
thor (0.14.6)
|
66
|
+
tzinfo (0.3.29)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
bundler (~> 1.0.0)
|
73
|
+
jasmine
|
74
|
+
jeweler (~> 1.6.4)
|
75
|
+
rspec
|
76
|
+
rspec-rails
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Leena
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
A gem that allows controller specs to generate markup which can be used as
|
2
|
+
HTML fixtures within javascript tests written using Jasmine and JSTestDriver.
|
3
|
+
|
4
|
+
To use this follow these steps:
|
5
|
+
|
6
|
+
1. Add the dependency for your gem in Gemfile:
|
7
|
+
|
8
|
+
gem 'js_fixtures'
|
9
|
+
|
10
|
+
2. Within the controller specs, call the method to create fixtures as follows:
|
11
|
+
|
12
|
+
save_fixture(html_for('body'),'Signup')
|
13
|
+
|
14
|
+
The above will save the content of the body in file Signup.js in the path 'spec/javascripts/helpers/'. The file will have a method loadSignupFixture which contains the HTML fixture.
|
15
|
+
3. Call the same in the JS tests in beforeEach section:
|
16
|
+
|
17
|
+
beforeEach(function () {
|
18
|
+
$(this).ready(function () {
|
19
|
+
loadSignupFixture()
|
20
|
+
});
|
21
|
+
});
|
22
|
+
|
23
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= js_fixtures
|
2
|
+
|
3
|
+
A gem that allows controller specs to generate markup which can be used as
|
4
|
+
HTML fixtures within javascript tests written using Jasmine and JSTestDriver.
|
5
|
+
|
6
|
+
To use this follow these steps:
|
7
|
+
|
8
|
+
* Add the dependency for your gem in Gemfile:
|
9
|
+
|
10
|
+
|
11
|
+
gem 'js_fixtures',:require => false
|
12
|
+
|
13
|
+
* Add the require in spec_helper.rb
|
14
|
+
|
15
|
+
require 'js_fixtures'
|
16
|
+
|
17
|
+
* Within the controller specs, call the method to create fixtures as follows:
|
18
|
+
|
19
|
+
save_fixture(html_for('body'),'Signup')
|
20
|
+
|
21
|
+
The above will save the content of the body in file Signup.js in the path 'spec/javascripts/helpers/'. The file will have a method loadSignupFixture which contains the HTML fixture.
|
22
|
+
|
23
|
+
* Call the same in the JS tests in beforeEach section:
|
24
|
+
|
25
|
+
beforeEach(function () {
|
26
|
+
$(this).ready(function () {
|
27
|
+
loadSignupFixture()
|
28
|
+
});
|
29
|
+
});
|
30
|
+
|
31
|
+
== Contributing to js_fixtures
|
32
|
+
|
33
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
34
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
35
|
+
* Fork the project
|
36
|
+
* Start a feature/bugfix branch
|
37
|
+
* Commit and push until you are happy with your contribution
|
38
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
39
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
40
|
+
|
41
|
+
== Copyright
|
42
|
+
|
43
|
+
Copyright (c) 2011 Multunus. See LICENSE.txt for
|
44
|
+
further details.
|
45
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "js_fixtures"
|
18
|
+
gem.homepage = "http://github.com/multunus/js_fixtures"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A gem to create HTML fixtures for JS Tests for Jasmine and JSTestDriver}
|
21
|
+
gem.description = %Q{A small utility which creates the HTML fixtures for Jasmine and JSTestDriver tests from the controller specs.}
|
22
|
+
gem.email = "leena.sn@multunus.com"
|
23
|
+
gem.authors = ["Leena"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/js_fixtures.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{js_fixtures}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Leena"]
|
12
|
+
s.date = %q{2011-08-01}
|
13
|
+
s.description = %q{A small utility which creates the HTML fixtures for Jasmine and JSTestDriver tests from the controller specs.}
|
14
|
+
s.email = %q{leena.sn@multunus.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"js_fixtures.gemspec",
|
30
|
+
"lib/js_fixtures.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/multunus/js_fixtures}
|
33
|
+
s.licenses = ["MIT"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.6.2}
|
36
|
+
s.summary = %q{A gem to create HTML fixtures for JS Tests for Jasmine and JSTestDriver}
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
s.specification_version = 3
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
+
s.add_runtime_dependency(%q<rspec>, [">= 0"])
|
43
|
+
s.add_runtime_dependency(%q<rspec-rails>, [">= 0"])
|
44
|
+
s.add_runtime_dependency(%q<jasmine>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
46
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
49
|
+
s.add_dependency(%q<rspec-rails>, [">= 0"])
|
50
|
+
s.add_dependency(%q<jasmine>, [">= 0"])
|
51
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rspec-rails>, [">= 0"])
|
57
|
+
s.add_dependency(%q<jasmine>, [">= 0"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/js_fixtures.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
RSpec::Rails::ControllerExampleGroup.class_eval do
|
2
|
+
|
3
|
+
# Saves the markup to a fixture file using the given name
|
4
|
+
def save_fixture(markup, name)
|
5
|
+
fixture_path = File.join(Rails.root.to_s, 'spec/javascripts/helpers')
|
6
|
+
Dir.mkdir(fixture_path) unless File.exists?(fixture_path)
|
7
|
+
|
8
|
+
fixture_file = File.join(fixture_path, "#{name}.js")
|
9
|
+
|
10
|
+
fixture_function = "function load#{name}Fixture(){
|
11
|
+
/*:DOC +="+markup+"*/
|
12
|
+
}"
|
13
|
+
File.open(fixture_file, 'w') do |file|
|
14
|
+
file.puts(fixture_function)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def save_js_fixture(markup, name)
|
19
|
+
fixture_path = File.join(Rails.root.to_s, 'spec/javascripts/helpers')
|
20
|
+
Dir.mkdir(fixture_path) unless File.exists?(fixture_path)
|
21
|
+
|
22
|
+
fixture_file = File.join(fixture_path, "#{name}.js")
|
23
|
+
|
24
|
+
File.open(fixture_file, 'w') do |file|
|
25
|
+
file.puts(markup)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# From the controller spec response body, extracts html identified
|
30
|
+
# by the css selector.
|
31
|
+
def html_for(selector)
|
32
|
+
doc = Nokogiri::HTML(response.body)
|
33
|
+
|
34
|
+
content = doc.css(selector).first.to_s
|
35
|
+
|
36
|
+
convert_body_tag_to_div(content)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Many of our css and jQuery selectors rely on a class attribute we
|
40
|
+
# normally embed in the <body>. For example:
|
41
|
+
#
|
42
|
+
# <body class="workspaces show">
|
43
|
+
#
|
44
|
+
# Here we convert the body tag to a div so that we can load it into
|
45
|
+
# the document running js specs without embedding a <body> within a <body>.
|
46
|
+
def convert_body_tag_to_div(markup)
|
47
|
+
markup.gsub("<body", '<div').gsub("</body>", "</div>")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: js_fixtures
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leena
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-01 00:00:00.000000000 +05:30
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: &74387410 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *74387410
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec-rails
|
28
|
+
requirement: &74385350 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *74385350
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: jasmine
|
39
|
+
requirement: &74383970 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *74383970
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: &74364840 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *74364840
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: jeweler
|
61
|
+
requirement: &74362220 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.6.4
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *74362220
|
70
|
+
description: A small utility which creates the HTML fixtures for Jasmine and JSTestDriver
|
71
|
+
tests from the controller specs.
|
72
|
+
email: leena.sn@multunus.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README
|
78
|
+
- README.rdoc
|
79
|
+
files:
|
80
|
+
- .document
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README
|
85
|
+
- README.rdoc
|
86
|
+
- Rakefile
|
87
|
+
- VERSION
|
88
|
+
- js_fixtures.gemspec
|
89
|
+
- lib/js_fixtures.rb
|
90
|
+
has_rdoc: true
|
91
|
+
homepage: http://github.com/multunus/js_fixtures
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
hash: -451846257
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.6.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: A gem to create HTML fixtures for JS Tests for Jasmine and JSTestDriver
|
119
|
+
test_files: []
|