jasmine-fixtures 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -21,3 +21,4 @@ pkg
21
21
  ## PROJECT::SPECIFIC
22
22
  .rvmrc
23
23
  .idea
24
+ .bundle
@@ -12,11 +12,18 @@ The gem includes 3 major pieces:
12
12
 
13
13
  == Installing
14
14
 
15
+ We're assuming you're on Rails 2.3.10, you've installed rspec, and you've installed the jasmine gem and run "script/generate jasmine".
16
+
15
17
  gem install jasmine-fixtures
16
18
 
17
19
  script/generate jasmine_fixtures
18
20
 
19
- If you want to use the fixture generator, you need to load jasmine_fixture_generator_methods.rb. If you load everything in your spec_helpers directory in your spec_helper.rb already, you're good to go. Otherwise, make sure it's required with the rest of your requires in spec_helper.rb.
21
+ If you want to use the fixture generator, you need to load jasmine_fixture_generator_methods.rb. If you load everything in your support directory in your spec_helper.rb already, you're good to go. Otherwise, make sure it's required with the rest of your requires in spec_helper.rb.
22
+
23
+ Once you run the generator, take a look at the added files to see how to generate and use the fixtures, especially
24
+ spec/controllers/jasmine_fixture_creators.rb
25
+ and
26
+ spec/javascripts/example-users-spec.js
20
27
 
21
28
  == Assumptions
22
29
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
@@ -4,6 +4,8 @@ class JasmineFixturesGenerator < Rails::Generator::Base
4
4
  m.directory "spec/javascripts/helpers"
5
5
  m.file "spec/javascripts/helpers/jasmine-fixture-helper.js", "spec/javascripts/helpers/jasmine-fixture-helper.js"
6
6
  m.file "spec/javascripts/helpers/jasmine-fixture-loader.js", "spec/javascripts/helpers/jasmine-fixture-loader.js"
7
+ m.file "spec/javascripts/helpers/jquery-matchers.js", "spec/javascripts/helpers/jquery-matchers.js"
8
+ m.file "spec/javascripts/example-users-spec.js", "spec/javascripts/example-users-spec.js"
7
9
 
8
10
  m.directory "spec/support"
9
11
  m.file "spec/support/jasmine_fixture_generator_methods.rb", "spec/support/jasmine_fixture_generator_methods.rb"
@@ -24,23 +24,21 @@ describe UsersController do
24
24
  #You need to integrate_views in each of your describes to get the content of the response
25
25
  integrate_views
26
26
 
27
- #Example of a standard request that would use html_for to strip <body>
28
- it "generates a new user page" do
29
- get :new
30
- response.should be_success
31
- save_fixture(html_for('body'), 'user-signup-page')
32
- end
33
-
34
- #Example of a logged-in ajax request that doesn't have a body tag to strip out
35
- describe "a user's profile" do
36
- before do
37
- log_in users(:james)
27
+ describe "user signup" do
28
+ #Example of a standard request that would use html_for to strip <body>
29
+ it "generates a new user signup page" do
30
+ get :new
31
+ response.should be_success
32
+ save_fixture(html_for('body'), 'user-signup-page')
38
33
  end
39
34
 
40
- it "generates a new user profile xhr" do
41
- xhr :get, :show, :id => users(:james).to_param
42
- response.should be_success
43
- save_fixture(response.body, 'user-profile-page')
35
+ #Example of an ajax request that doesn't have a body tag to strip out
36
+ describe "a user's profile" do
37
+ it "generates successful signup xhr response" do
38
+ xhr :post, :create, :user => { :name => 'Bob', :password => 'something', :password_confirmation => 'something' }
39
+ response.should be_success
40
+ save_fixture(response.body, 'user-success-ajax-response')
41
+ end
44
42
  end
45
43
  end
46
44
  end
@@ -0,0 +1,21 @@
1
+ // Here is an example of how you might use the fixtures in your jasmine tests. Obviously this test won't actually work
2
+ // in your project.
3
+ describe('User pages', function () {
4
+ describe('the signup page', function() {
5
+ it('looks correct', function() {
6
+ spec.loadFixture('user-signup-page');
7
+ expect($("#some_id")).toExist();
8
+ });
9
+ });
10
+
11
+ describe('user signup success page load over ajax', function() {
12
+ it('inserts the returned content into the page', function() {
13
+ spec.loadFixture('user-signup-page');
14
+ var fixtureData = spec.readFixture('user-success-ajax-response');
15
+ doSomethingInvolvingAnAjaxCallThatReceivesHTML();
16
+ $.ajax.mostRecentCall.args[0].success(fixtureData);
17
+ expect($("#some_id_in_the_ajax_response")).toExist();
18
+ expect(somethingExcitingToHaveHappened()).toBeTruthy();
19
+ });
20
+ });
21
+ });
@@ -15,7 +15,7 @@ afterEach(function() {
15
15
 
16
16
  spec.cleanupHooks = function() {
17
17
  // clearLiveEventBindings is helpful if using jQuery live events, uncomment if you'd like to use it.
18
- // spec.clearLiveEventBindings();
18
+ // spec.clearLiveEventBindings();
19
19
  };
20
20
 
21
21
  spec.clearLiveEventBindings = function() {
@@ -0,0 +1,133 @@
1
+ // This is Wojciech's jasmine-jquery library without the fixtures. See https://github.com/velesin/jasmine-jquery
2
+
3
+ // Copyright (c) 2010 Wojciech Zawistowski
4
+ //
5
+ // Permission is hereby granted, free of charge, to any person obtaining
6
+ // a copy of this software and associated documentation files (the
7
+ // "Software"), to deal in the Software without restriction, including
8
+ // without limitation the rights to use, copy, modify, merge, publish,
9
+ // distribute, sublicense, and/or sell copies of the Software, and to
10
+ // permit persons to whom the Software is furnished to do so, subject to
11
+ // the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be
14
+ // included in all copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ jasmine.JQuery = function() {};
25
+
26
+ jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
27
+ return $('<div/>').append(html).html();
28
+ };
29
+
30
+ jasmine.JQuery.elementToString = function(element) {
31
+ return $('<div />').append(element.clone()).html();
32
+ };
33
+
34
+ jasmine.JQuery.matchersClass = {};
35
+
36
+ (function(){
37
+ var jQueryMatchers = {
38
+ toHaveClass: function(className) {
39
+ return this.actual.hasClass(className);
40
+ },
41
+
42
+ toBeVisible: function() {
43
+ return this.actual.is(':visible');
44
+ },
45
+
46
+ toBeHidden: function() {
47
+ return this.actual.is(':hidden');
48
+ },
49
+
50
+ toBeSelected: function() {
51
+ return this.actual.is(':selected');
52
+ },
53
+
54
+ toBeChecked: function() {
55
+ return this.actual.is(':checked');
56
+ },
57
+
58
+ toBeEmpty: function() {
59
+ return this.actual.is(':empty');
60
+ },
61
+
62
+ toExist: function() {
63
+ return this.actual.size() > 0;
64
+ },
65
+
66
+ toHaveAttr: function(attributeName, expectedAttributeValue) {
67
+ return hasProperty(this.actual.attr(attributeName), expectedAttributeValue);
68
+ },
69
+
70
+ toHaveId: function(id) {
71
+ return this.actual.attr('id') == id;
72
+ },
73
+
74
+ toHaveHtml: function(html) {
75
+ return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html);
76
+ },
77
+
78
+ toHaveText: function(text) {
79
+ return this.actual.text() == text;
80
+ },
81
+
82
+ toHaveValue: function(value) {
83
+ return this.actual.val() == value;
84
+ },
85
+
86
+ toHaveData: function(key, expectedValue) {
87
+ return hasProperty(this.actual.data(key), expectedValue);
88
+ },
89
+
90
+ toBe: function(selector) {
91
+ return this.actual.is(selector);
92
+ },
93
+
94
+ toContain: function(selector) {
95
+ return this.actual.find(selector).size() > 0;
96
+ }
97
+ };
98
+
99
+ var hasProperty = function(actualValue, expectedValue) {
100
+ if (expectedValue === undefined) {
101
+ return actualValue !== undefined;
102
+ }
103
+ return actualValue == expectedValue;
104
+ };
105
+
106
+ var bindMatcher = function(methodName) {
107
+ var builtInMatcher = jasmine.Matchers.prototype[methodName];
108
+
109
+ jasmine.JQuery.matchersClass[methodName] = function() {
110
+ if (this.actual instanceof jQuery) {
111
+ var result = jQueryMatchers[methodName].apply(this, arguments);
112
+ this.actual = jasmine.JQuery.elementToString(this.actual);
113
+ return result;
114
+ }
115
+
116
+ if (builtInMatcher) {
117
+ return builtInMatcher.apply(this, arguments);
118
+ } else {
119
+ throw ("There is no " + methodName + " method on this object. Did you forget a $ jQuery call in your expect?"); // Added to help debugging.
120
+ }
121
+
122
+ return false;
123
+ };
124
+ };
125
+
126
+ for(var methodName in jQueryMatchers) {
127
+ bindMatcher(methodName);
128
+ }
129
+ })();
130
+
131
+ beforeEach(function() {
132
+ this.addMatchers(jasmine.JQuery.matchersClass);
133
+ });
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jasmine-fixtures}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roger Neel", "Jonathan Barnes", "JB Steadman", "Andrew Cantino"]
12
- s.date = %q{2010-11-08}
12
+ s.date = %q{2011-01-27}
13
13
  s.description = %q{Dump out DOM that you want to test. Use jasmine-fixtures to load that DOM into your Jasmine specs. See http://github.com/mavenlink/jasmine-fixtures for more.}
14
14
  s.email = %q{roger@mavenlink.com}
15
15
  s.extra_rdoc_files = [
@@ -30,24 +30,18 @@ Gem::Specification.new do |s|
30
30
  "generators/jasmine-fixtures/jasmine_fixtures_generator.rb",
31
31
  "generators/jasmine-fixtures/templates/INSTALL",
32
32
  "generators/jasmine-fixtures/templates/spec/controllers/jasmine_fixture_creators.rb",
33
+ "generators/jasmine-fixtures/templates/spec/javascripts/example-users-spec.js",
33
34
  "generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-helper.js",
34
35
  "generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-loader.js",
36
+ "generators/jasmine-fixtures/templates/spec/javascripts/helpers/jquery-matchers.js",
35
37
  "generators/jasmine-fixtures/templates/spec/support/jasmine_fixture_generator_methods.rb",
36
- "jasmine-fixtures.gemspec",
37
- "lib/jasmine-fixtures.rb",
38
- "spec/jasmine-fixtures_spec.rb",
39
- "spec/spec.opts",
40
- "spec/spec_helper.rb"
38
+ "jasmine-fixtures.gemspec"
41
39
  ]
42
40
  s.homepage = %q{http://github.com/mavenlink/jasmine-fixtures}
43
41
  s.rdoc_options = ["--charset=UTF-8"]
44
42
  s.require_paths = ["lib"]
45
43
  s.rubygems_version = %q{1.3.7}
46
44
  s.summary = %q{Jasmine Fixtures allow you to use real DOM to test your JavaScript}
47
- s.test_files = [
48
- "spec/jasmine-fixtures_spec.rb",
49
- "spec/spec_helper.rb"
50
- ]
51
45
 
52
46
  if s.respond_to? :specification_version then
53
47
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine-fixtures
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roger Neel
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-11-08 00:00:00 -08:00
21
+ date: 2011-01-27 00:00:00 -08:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -106,14 +106,12 @@ files:
106
106
  - generators/jasmine-fixtures/jasmine_fixtures_generator.rb
107
107
  - generators/jasmine-fixtures/templates/INSTALL
108
108
  - generators/jasmine-fixtures/templates/spec/controllers/jasmine_fixture_creators.rb
109
+ - generators/jasmine-fixtures/templates/spec/javascripts/example-users-spec.js
109
110
  - generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-helper.js
110
111
  - generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-loader.js
112
+ - generators/jasmine-fixtures/templates/spec/javascripts/helpers/jquery-matchers.js
111
113
  - generators/jasmine-fixtures/templates/spec/support/jasmine_fixture_generator_methods.rb
112
114
  - jasmine-fixtures.gemspec
113
- - lib/jasmine-fixtures.rb
114
- - spec/jasmine-fixtures_spec.rb
115
- - spec/spec.opts
116
- - spec/spec_helper.rb
117
115
  has_rdoc: true
118
116
  homepage: http://github.com/mavenlink/jasmine-fixtures
119
117
  licenses: []
@@ -148,6 +146,5 @@ rubygems_version: 1.3.7
148
146
  signing_key:
149
147
  specification_version: 3
150
148
  summary: Jasmine Fixtures allow you to use real DOM to test your JavaScript
151
- test_files:
152
- - spec/jasmine-fixtures_spec.rb
153
- - spec/spec_helper.rb
149
+ test_files: []
150
+
File without changes
@@ -1,7 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "JasmineFixtures" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
6
- end
7
- end
@@ -1 +0,0 @@
1
- --color
@@ -1,9 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'jasmine-fixtures'
4
- require 'spec'
5
- require 'spec/autorun'
6
-
7
- Spec::Runner.configure do |config|
8
-
9
- end