sinatra-tests 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +165 -12
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/lib/sinatra/tests.rb +4 -2
- data/lib/sinatra/tests/rspec/matchers.rb +224 -0
- data/lib/sinatra/tests/rspec/shared_specs.rb +342 -0
- data/sinatra-tests.gemspec +22 -17
- data/spec/sinatra/tests/rspec/matchers_spec.rb +274 -0
- data/spec/sinatra/tests/test_case_spec.rb +0 -15
- data/spec/sinatra/tests/tests_spec.rb +30 -0
- data/spec/spec_helper.rb +7 -9
- metadata +52 -26
- data/lib/sinatra/tests/init.rb +0 -174
- data/lib/sinatra/tests/shared_specs.rb +0 -450
@@ -5,21 +5,9 @@ require "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/../spec_helpe
|
|
5
5
|
describe "Sinatra" do
|
6
6
|
|
7
7
|
it_should_behave_like "MyTestApp"
|
8
|
-
# it_should_behave_like "MyAdminTestApp"
|
9
|
-
|
10
|
-
# it_should_behave_like "debug => app.methods"
|
11
8
|
|
12
9
|
describe "Tests" do
|
13
10
|
|
14
|
-
describe "#self.version" do
|
15
|
-
|
16
|
-
it "should return a string with the version number" do
|
17
|
-
Sinatra::Tests.version.should match(/Sinatra::Tests v\d\.\d\.\d/)
|
18
|
-
end
|
19
|
-
|
20
|
-
end #/ #version
|
21
|
-
|
22
|
-
|
23
11
|
describe "TestCase" do
|
24
12
|
|
25
13
|
describe "#h" do
|
@@ -100,7 +88,6 @@ describe "Sinatra" do
|
|
100
88
|
end
|
101
89
|
|
102
90
|
it "should work with a custom URL" do
|
103
|
-
pending "these tests does not really work. Find out why"
|
104
91
|
class MyTestApp
|
105
92
|
get '/custom-haml-url' do
|
106
93
|
haml "%customurl= @params[:view]"
|
@@ -114,9 +101,7 @@ describe "Sinatra" do
|
|
114
101
|
|
115
102
|
end #/ #haml_app
|
116
103
|
|
117
|
-
|
118
104
|
end #/ TestCase
|
119
105
|
|
120
|
-
|
121
106
|
end #/ Tests
|
122
107
|
end #/ Sinatra
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
require "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/../spec_helper"
|
3
|
+
|
4
|
+
|
5
|
+
describe "Sinatra" do
|
6
|
+
|
7
|
+
it_should_behave_like "MyTestApp"
|
8
|
+
|
9
|
+
describe "Tests" do
|
10
|
+
|
11
|
+
describe "VERSION" do
|
12
|
+
|
13
|
+
it "should return the VERSION string" do
|
14
|
+
Sinatra::Tests::VERSION.should be_a_kind_of(String)
|
15
|
+
Sinatra::Tests::VERSION.should match(/\d\.\d+\.\d+(\.\d)?/)
|
16
|
+
end
|
17
|
+
|
18
|
+
end #/ VERSION
|
19
|
+
|
20
|
+
describe "#self.version" do
|
21
|
+
|
22
|
+
it "should return a string with the version number" do
|
23
|
+
Sinatra::Tests.version.should match(/Sinatra::Tests v\d\.\d\.\d/)
|
24
|
+
end
|
25
|
+
|
26
|
+
end #/ #version
|
27
|
+
|
28
|
+
end #/ Tests
|
29
|
+
|
30
|
+
end #/ Sinatra
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
-
require 'spec'
|
1
|
+
# require 'spec'
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
4
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
5
|
require 'sinatra/tests'
|
6
6
|
|
7
|
+
|
8
|
+
ENV['RACK_ENV'] = 'test'
|
9
|
+
|
7
10
|
Spec::Runner.configure do |config|
|
8
11
|
config.include RspecHpricotMatchers
|
9
|
-
config.include Sinatra::Tests::
|
12
|
+
config.include Sinatra::Tests::TestCase
|
13
|
+
config.include Sinatra::Tests::RSpec::SharedSpecs
|
10
14
|
end
|
11
15
|
|
12
16
|
|
@@ -19,15 +23,9 @@ end
|
|
19
23
|
class MyTestApp < Sinatra::Base
|
20
24
|
register(Sinatra::Tests)
|
21
25
|
end
|
22
|
-
|
23
|
-
class MyAdminTestApp < MyTestApp
|
24
|
-
# register(Sinatra::Tests)
|
25
|
-
end
|
26
26
|
|
27
27
|
|
28
28
|
class Test::Unit::TestCase
|
29
|
-
include Sinatra::Tests::TestCase
|
30
|
-
|
31
29
|
Sinatra::Base.set :environment, :test
|
32
|
-
|
33
30
|
end
|
31
|
+
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-tests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- kematzy
|
@@ -9,49 +14,64 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-02-23 00:00:00 +08:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: sinatra
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 10
|
30
|
+
- 1
|
23
31
|
version: 0.10.1
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: rack-test
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 5
|
44
|
+
- 3
|
45
|
+
version: 0.5.3
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: rspec
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
52
|
requirements:
|
41
53
|
- - ">="
|
42
54
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 3
|
58
|
+
- 0
|
59
|
+
version: 1.3.0
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
45
62
|
- !ruby/object:Gem::Dependency
|
46
63
|
name: rspec_hpricot_matchers
|
47
|
-
|
48
|
-
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
66
|
requirements:
|
51
67
|
- - ">="
|
52
68
|
- !ruby/object:Gem::Version
|
53
|
-
|
54
|
-
|
69
|
+
segments:
|
70
|
+
- 1
|
71
|
+
- 0
|
72
|
+
version: "1.0"
|
73
|
+
type: :runtime
|
74
|
+
version_requirements: *id004
|
55
75
|
description:
|
56
76
|
email: kematzy@gmail.com
|
57
77
|
executables: []
|
@@ -69,11 +89,13 @@ files:
|
|
69
89
|
- Rakefile
|
70
90
|
- VERSION
|
71
91
|
- lib/sinatra/tests.rb
|
72
|
-
- lib/sinatra/tests/
|
73
|
-
- lib/sinatra/tests/shared_specs.rb
|
92
|
+
- lib/sinatra/tests/rspec/matchers.rb
|
93
|
+
- lib/sinatra/tests/rspec/shared_specs.rb
|
74
94
|
- lib/sinatra/tests/test_case.rb
|
75
95
|
- sinatra-tests.gemspec
|
96
|
+
- spec/sinatra/tests/rspec/matchers_spec.rb
|
76
97
|
- spec/sinatra/tests/test_case_spec.rb
|
98
|
+
- spec/sinatra/tests/tests_spec.rb
|
77
99
|
- spec/spec_helper.rb
|
78
100
|
has_rdoc: true
|
79
101
|
homepage: http://github.com/kematzy/sinatra-tests
|
@@ -88,21 +110,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
110
|
requirements:
|
89
111
|
- - ">="
|
90
112
|
- !ruby/object:Gem::Version
|
113
|
+
segments:
|
114
|
+
- 0
|
91
115
|
version: "0"
|
92
|
-
version:
|
93
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
117
|
requirements:
|
95
118
|
- - ">="
|
96
119
|
- !ruby/object:Gem::Version
|
120
|
+
segments:
|
121
|
+
- 0
|
97
122
|
version: "0"
|
98
|
-
version:
|
99
123
|
requirements: []
|
100
124
|
|
101
125
|
rubyforge_project:
|
102
|
-
rubygems_version: 1.3.
|
126
|
+
rubygems_version: 1.3.6
|
103
127
|
signing_key:
|
104
128
|
specification_version: 3
|
105
129
|
summary: Sinatra::Tests is a repository of common Test/RSpec helpers
|
106
130
|
test_files:
|
131
|
+
- spec/sinatra/tests/rspec/matchers_spec.rb
|
107
132
|
- spec/sinatra/tests/test_case_spec.rb
|
133
|
+
- spec/sinatra/tests/tests_spec.rb
|
108
134
|
- spec/spec_helper.rb
|
data/lib/sinatra/tests/init.rb
DELETED
@@ -1,174 +0,0 @@
|
|
1
|
-
|
2
|
-
# ### Make sure my own gem path is included first
|
3
|
-
# if (ENV['HOME'] =~ /^\/home\//) ## DREAMHOST
|
4
|
-
# ENV['GEM_HOME'] = "#{ENV['HOME']}/.gems"
|
5
|
-
# ENV['GEM_PATH'] = "#{ENV['HOME']}/.gems:/usr/lib/ruby/gems/1.8"
|
6
|
-
# require 'rubygems'
|
7
|
-
# Gem.clear_paths
|
8
|
-
# else
|
9
|
-
# require 'rubygems'
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# #--
|
13
|
-
# # DEPENDENCIES
|
14
|
-
# #++
|
15
|
-
#
|
16
|
-
# require 'haml'
|
17
|
-
# require 'sass'
|
18
|
-
# require 'sinatra/base'
|
19
|
-
# require 'alt/rext'
|
20
|
-
# require 'ostruct'
|
21
|
-
# require 'yaml'
|
22
|
-
#
|
23
|
-
# #--
|
24
|
-
# ## SINATRA EXTENSIONS
|
25
|
-
# #++
|
26
|
-
#
|
27
|
-
# require 'sinatra/basics'
|
28
|
-
# require 'sinatra/ie6nomore'
|
29
|
-
# # require 'sinatra/upload'
|
30
|
-
# # require 'sinatra/snippets'
|
31
|
-
# #require 'sinatra/cache'
|
32
|
-
#
|
33
|
-
# #--
|
34
|
-
# # DATABASE DEPENDENCIES
|
35
|
-
# #++
|
36
|
-
# require 'dm-core'
|
37
|
-
# require 'dm-migrations'
|
38
|
-
# require 'dm-timestamps'
|
39
|
-
# require 'dm-validations'
|
40
|
-
# require 'dm-serializer'
|
41
|
-
# require 'dm-types'
|
42
|
-
#
|
43
|
-
# #--
|
44
|
-
# # DATABASE CONFIGURATION
|
45
|
-
# #++
|
46
|
-
#
|
47
|
-
# DataMapper::Logger.new("#{APP_ROOT}/db/dm.app.log", :debug)
|
48
|
-
# DataMapper.setup :default, "sqlite3://#{APP_ROOT}/db/db.tests.db"
|
49
|
-
# DataMapper.auto_upgrade!
|
50
|
-
#
|
51
|
-
#--
|
52
|
-
# SINATRA::TESTS::INIT
|
53
|
-
#
|
54
|
-
# Main Extension that loads a number of commonly used parts / functionality
|
55
|
-
#++
|
56
|
-
|
57
|
-
module Sinatra::Tests
|
58
|
-
module Init
|
59
|
-
|
60
|
-
module Helpers
|
61
|
-
|
62
|
-
##
|
63
|
-
# Convenience method for the class Settings block
|
64
|
-
def konf
|
65
|
-
self.class.settings
|
66
|
-
end
|
67
|
-
|
68
|
-
end #/module Helpers
|
69
|
-
|
70
|
-
def self.registered(app)
|
71
|
-
app.helpers Sinatra::Init::Helpers
|
72
|
-
|
73
|
-
## OPTIONS / SINATRA / CORE
|
74
|
-
app.set :static, true
|
75
|
-
app.set :logging, true
|
76
|
-
app.set :sessions, true
|
77
|
-
app.set :methodoverride, true
|
78
|
-
app.set :run, false
|
79
|
-
|
80
|
-
app.set :raise_errors, true #Proc.new { test? }
|
81
|
-
app.set :show_exceptions, true #Proc.new { development? }
|
82
|
-
|
83
|
-
## OPTIONS / SINATRA / EXTENSIONS
|
84
|
-
# app.set :admin_path_prefix, '/admin'
|
85
|
-
|
86
|
-
## OPTIONS / SINATRA / APP
|
87
|
-
|
88
|
-
app.set :apps_dir, "#{APP_ROOT}/apps"
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
##
|
93
|
-
# Configuration loading abstraction. Loads the configurations in the given path,
|
94
|
-
# or
|
95
|
-
#
|
96
|
-
# ==== Examples
|
97
|
-
#
|
98
|
-
# set :settings, load_settings('/path/2/configurations/file.yml')
|
99
|
-
#
|
100
|
-
# Merge local settings with the global configurations, via adding :merge_with_global
|
101
|
-
#
|
102
|
-
# set :settings, load_settings('/path/2/configurations/file.yml', :merge_with_global)
|
103
|
-
#
|
104
|
-
#
|
105
|
-
# @api public
|
106
|
-
def load_settings!(path, load_global = nil)
|
107
|
-
global_settings = load_global.nil? ? {} : YAML.load_file("#{APP_ROOT}/config/settings.yml")
|
108
|
-
loaded_settings = test(?f, path) ? YAML.load_file(path) : {} # Hash coming in
|
109
|
-
merged_settings = global_settings.merge(loaded_settings)
|
110
|
-
puts "- Settings loaded and merged for [#{path.sub(APP_ROOT,'')}]"
|
111
|
-
@settings = ::OpenStruct.new(merged_settings)
|
112
|
-
end
|
113
|
-
|
114
|
-
##
|
115
|
-
# Convenience method for loading declared routes.
|
116
|
-
#
|
117
|
-
# Takes the full path to the apps/app directory
|
118
|
-
#
|
119
|
-
# ==== Examples
|
120
|
-
#
|
121
|
-
# load_routes!(app_dir)
|
122
|
-
#
|
123
|
-
#
|
124
|
-
# load_routes!('/full/path/2/apps/app/dir')
|
125
|
-
#
|
126
|
-
# @api public
|
127
|
-
def load_routes!(app_dir_path)
|
128
|
-
# puts "load_routes!(app_dir_path=[#{app_dir_path}]) [#{__FILE__}:#{__LINE__}]"
|
129
|
-
Dir["#{app_dir_path}/routes/*.rb"].each do |route|
|
130
|
-
load route
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
##
|
135
|
-
# Convenience method for loading helpers.
|
136
|
-
#
|
137
|
-
# Takes the full path to the apps/app directory
|
138
|
-
#
|
139
|
-
# ==== Examples
|
140
|
-
#
|
141
|
-
# load_helpers!(app_dir)
|
142
|
-
#
|
143
|
-
#
|
144
|
-
# load_helpers!('/full/path/2/apps/app/dir')
|
145
|
-
#
|
146
|
-
# @api public
|
147
|
-
def load_helpers!(app_dir_path)
|
148
|
-
# puts "load_helpers!(app_dir_path=[#{app_dir_path}]) [#{__FILE__}:#{__LINE__}]"
|
149
|
-
Dir["#{app_dir_path}/helpers/*.rb"].each do |helper|
|
150
|
-
load helper
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
##
|
155
|
-
# Convenience method for loading models.
|
156
|
-
#
|
157
|
-
# Takes the full path to the apps/app directory
|
158
|
-
#
|
159
|
-
# ==== Examples
|
160
|
-
#
|
161
|
-
# load_models!(app_dir)
|
162
|
-
#
|
163
|
-
#
|
164
|
-
# load_models!('/full/path/2/apps/app/dir')
|
165
|
-
#
|
166
|
-
# @api public
|
167
|
-
def load_models!(app_dir)
|
168
|
-
Dir["#{app_dir}/models/*.rb"].each do |model|
|
169
|
-
load model
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
end #/module Init
|
174
|
-
end #/module Sinatra::Tests
|
@@ -1,450 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Sinatra
|
4
|
-
module Tests
|
5
|
-
|
6
|
-
module RSpecMatchers
|
7
|
-
|
8
|
-
##
|
9
|
-
# TODO: add some comments here
|
10
|
-
#
|
11
|
-
# ==== Examples
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# @api public/private
|
15
|
-
def be_even
|
16
|
-
simple_matcher("an even number") { |given| given % 2 == 0 }
|
17
|
-
end
|
18
|
-
|
19
|
-
##
|
20
|
-
# TODO: add some comments here
|
21
|
-
#
|
22
|
-
# ==== Examples
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# @api public/private
|
26
|
-
def have_a_page_title(expected)
|
27
|
-
simple_matcher do |given, matcher|
|
28
|
-
given.should have_tag('title', expected)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
##
|
33
|
-
# TODO: add some comments here
|
34
|
-
#
|
35
|
-
# ==== Examples
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# @api public/private
|
39
|
-
def have_a_page_header(expected)
|
40
|
-
simple_matcher("have an h2 page header with [#{expected.inspect}]") do |given, matcher|
|
41
|
-
# matcher.description = "have an h2 page header with [#{expected.inspect}]"
|
42
|
-
given.should have_tag('h2', expected, :count => 1)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
##
|
47
|
-
# TODO: add some comments here
|
48
|
-
#
|
49
|
-
# ==== Examples
|
50
|
-
#
|
51
|
-
#
|
52
|
-
# @api public/private
|
53
|
-
def have_a_td_actions(model, buttons = %w(delete edit))
|
54
|
-
simple_matcher do |given, matcher|
|
55
|
-
tag = "div##{model.to_s.plural}-div > table##{model.to_s.plural}-table > tbody > tr > td.actions"
|
56
|
-
given.should have_tag(tag) do |td|
|
57
|
-
td.attributes['id'].should match(/#{model.to_s.singular}-actions-\d+/)
|
58
|
-
end
|
59
|
-
buttons.each do |btn|
|
60
|
-
given.should have_a_delete_btn(tag, model) if btn.to_s == 'delete'
|
61
|
-
given.should have_an_edit_btn(tag, model) if btn.to_s == 'edit'
|
62
|
-
# TODO:: fix Show button
|
63
|
-
# td.should have_a_show_btn(model) if btn.to_s == 'show'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
##
|
69
|
-
# TODO: add some comments here
|
70
|
-
#
|
71
|
-
# ==== Examples
|
72
|
-
#
|
73
|
-
#
|
74
|
-
# @api public/private
|
75
|
-
def have_an_edit_btn(tag, model)
|
76
|
-
simple_matcher do |given, matcher|
|
77
|
-
given.should have_tag(tag + ' > a.edit-link.ui-btn','EDIT') do |a|
|
78
|
-
a.attributes['href'].should match(/\/#{model.to_s.plural}\/\d+\/edit/)
|
79
|
-
end
|
80
|
-
given.should have_tag(tag + " > a.edit-link[@title=edit #{model.to_s.singular}]",'EDIT')
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
##
|
85
|
-
# TODO: add some comments here
|
86
|
-
#
|
87
|
-
# ==== Examples
|
88
|
-
#
|
89
|
-
#
|
90
|
-
# @api public/private
|
91
|
-
def have_a_delete_btn(tag, model)
|
92
|
-
simple_matcher do |given, matcher|
|
93
|
-
given.should have_tag(tag + ' > a.delete-link.ui-btn','DELETE') do |a|
|
94
|
-
a.attributes['href'].should match(/\/#{model.to_s.plural}\/\d+/)
|
95
|
-
end
|
96
|
-
given.should have_tag(tag + " > a.delete-link[@title=delete #{model.to_s.singular}]",'DELETE')
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# def have_id_attribute(tag, id)
|
101
|
-
# simple_matcher do |given, matcher|
|
102
|
-
# given.should have_tag(tag).attributes['id'].should match(id)
|
103
|
-
# end
|
104
|
-
# end
|
105
|
-
|
106
|
-
# def have_link_title(title)
|
107
|
-
# simple_matcher do |given, matcher|
|
108
|
-
# given.attributes['title'].should == title
|
109
|
-
# end
|
110
|
-
# end
|
111
|
-
|
112
|
-
##
|
113
|
-
# TODO: add some comments here
|
114
|
-
#
|
115
|
-
# ==== Examples
|
116
|
-
#
|
117
|
-
#
|
118
|
-
# @api public/private
|
119
|
-
def have_an_ui_form_header(model, options = {} )
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
##
|
124
|
-
# TODO: add some comments here
|
125
|
-
#
|
126
|
-
# ==== Examples
|
127
|
-
#
|
128
|
-
#
|
129
|
-
# @api public/private
|
130
|
-
def have_a_ui_form_message(state, msg = nil)
|
131
|
-
simple_matcher do |given, matcher|
|
132
|
-
if msg.nil?
|
133
|
-
given.should have_tag("form > div.ui-form-message.#{state} > p") #ignoring message
|
134
|
-
else
|
135
|
-
given.should have_tag("form > div.ui-form-message.#{state} > p", msg)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
##
|
141
|
-
# TODO: add some comments here
|
142
|
-
#
|
143
|
-
# ==== Examples
|
144
|
-
#
|
145
|
-
#
|
146
|
-
# @api public/private
|
147
|
-
def have_an_admin_header(options ={})
|
148
|
-
simple_matcher do |given, matcher|
|
149
|
-
matcher.description = "be an admin_header with [#{options.inspect}]"
|
150
|
-
matcher.failure_message = "expected #{given} to have an admin-section-header with these values #{options.inspect}"
|
151
|
-
|
152
|
-
given.should have_tag('div.admin-section-header')
|
153
|
-
if options[:model]
|
154
|
-
given.should have_tag('div.admin-section-header > div.section > h2', /#{options[:model].to_s}/i )
|
155
|
-
if options[:add_new]
|
156
|
-
given.should have_tag("div.admin-section-header > div.actions > h4 > a[@href=/#{options[:model].to_s.downcase}/new]", /ADD NEW #{options[:model].to_s.singular}:?/i )
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
end #/module RSpecMatchers
|
164
|
-
|
165
|
-
# == Shared Specs
|
166
|
-
#
|
167
|
-
# === DEBUG
|
168
|
-
#
|
169
|
-
# * <b><tt>it_should_behave_like "debug => app.methods"</tt></b>
|
170
|
-
#
|
171
|
-
# dumps a list of methods for the current <tt>app</tt>
|
172
|
-
#
|
173
|
-
# * <b><tt>it_should_behave_like "debug"</tt></b>
|
174
|
-
#
|
175
|
-
# tests the body output for a <tt><debug></tt> tag.
|
176
|
-
#
|
177
|
-
#
|
178
|
-
# === RESPONSE
|
179
|
-
#
|
180
|
-
# * <b><tt>it_should_behave_like "HTTP headers"</tt></b>
|
181
|
-
#
|
182
|
-
# checks that we got a 200 status (OK), and content-type is <tt>text/html</tt>
|
183
|
-
#
|
184
|
-
#
|
185
|
-
# === HTML OUTPUT
|
186
|
-
#
|
187
|
-
# * <b><tt>it_should_behave_like "div#main-content"</tt></b>
|
188
|
-
#
|
189
|
-
# checks that the page has a <tt><div id="main-content"></div></tt>
|
190
|
-
#
|
191
|
-
# * <b><tt>it_should_behave_like "div#main-content > h2"</tt></b>
|
192
|
-
#
|
193
|
-
# checks that the page has an <tt><h2></tt> tag within the <tt><div id="main-content"></div></tt>
|
194
|
-
#
|
195
|
-
#
|
196
|
-
# ==== ADMIN SECTION
|
197
|
-
#
|
198
|
-
# * <b><tt>it_should_behave_like "div.admin-section-header > div.actions > h4 with HELP"</tt></b>
|
199
|
-
#
|
200
|
-
# checks that the page has an...
|
201
|
-
#
|
202
|
-
#
|
203
|
-
# ==== FORMS
|
204
|
-
#
|
205
|
-
# * <b><tt>it_should_behave_like "faux method > input.hidden[@value=put|delete]"</tt></b>
|
206
|
-
#
|
207
|
-
# checks that the page has an...
|
208
|
-
#
|
209
|
-
module SharedSpecs
|
210
|
-
|
211
|
-
include Sinatra::Tests::RSpecMatchers
|
212
|
-
|
213
|
-
# :stopdoc:
|
214
|
-
|
215
|
-
share_examples_for 'MyTestApp' do
|
216
|
-
|
217
|
-
before(:each) do
|
218
|
-
class ::Test::Unit::TestCase
|
219
|
-
def app; ::MyTestApp.new ; end
|
220
|
-
end
|
221
|
-
@app = app
|
222
|
-
end
|
223
|
-
|
224
|
-
after(:each) do
|
225
|
-
class ::Test::Unit::TestCase
|
226
|
-
def app; nil ; end
|
227
|
-
end
|
228
|
-
@app = nil
|
229
|
-
end
|
230
|
-
|
231
|
-
describe "Sanity" do
|
232
|
-
|
233
|
-
it "should be a MyTestApp kind of app" do
|
234
|
-
# FIXME:: HACK to prevent errors due to stupid Rack::CommonLogger error, when testing.
|
235
|
-
unless app.class == MyTestApp
|
236
|
-
pending "app.class returns [#{app.class}]"
|
237
|
-
else
|
238
|
-
app.class.should == MyTestApp
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
# it_should_behave_like "debug => app.methods"
|
243
|
-
|
244
|
-
end #/ Sanity
|
245
|
-
|
246
|
-
end
|
247
|
-
|
248
|
-
share_examples_for 'MyAdminTestApp' do
|
249
|
-
|
250
|
-
before(:each) do
|
251
|
-
class ::Test::Unit::TestCase
|
252
|
-
def app; ::MyAdminTestApp.new ; end
|
253
|
-
end
|
254
|
-
@app = app
|
255
|
-
end
|
256
|
-
|
257
|
-
after(:each) do
|
258
|
-
class ::Test::Unit::TestCase
|
259
|
-
def app; nil ; end
|
260
|
-
end
|
261
|
-
@app = nil
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
# :startdoc:
|
266
|
-
|
267
|
-
# it_should_behave_like "debug => app.methods"
|
268
|
-
#
|
269
|
-
share_examples_for "debug => app.methods" do
|
270
|
-
it "app should have the right methods" do
|
271
|
-
app.methods.sort.should == 'debug => app.methods.sort'
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
share_examples_for "debug" do
|
276
|
-
|
277
|
-
it "should output the whole html" do
|
278
|
-
body.should have_tag('debug')
|
279
|
-
end
|
280
|
-
|
281
|
-
end #/debug
|
282
|
-
|
283
|
-
share_examples_for "HTTP headers" do
|
284
|
-
|
285
|
-
it "should return status: 200" do
|
286
|
-
assert response.ok?
|
287
|
-
end
|
288
|
-
|
289
|
-
it "should return 'text/html'" do
|
290
|
-
response.headers['Content-Type'].should == 'text/html'
|
291
|
-
# assert_equal('text/html', last_response.headers['Content-Type'])
|
292
|
-
end
|
293
|
-
|
294
|
-
end #/headers
|
295
|
-
|
296
|
-
|
297
|
-
###### HTML OUTPUT #######
|
298
|
-
|
299
|
-
share_examples_for 'div#main-content' do
|
300
|
-
it "should have a div#main-content tag" do
|
301
|
-
body.should have_tag('div#main-content')
|
302
|
-
end
|
303
|
-
end #/div
|
304
|
-
|
305
|
-
share_examples_for 'div#main-content > h2' do
|
306
|
-
it "should have a div#main-content h2 tag" do
|
307
|
-
body.should have_tag('div#main-content > h2', :count => 1)
|
308
|
-
end
|
309
|
-
end #/share_examples_for
|
310
|
-
|
311
|
-
|
312
|
-
###### ADMIN SECTIONS #######
|
313
|
-
|
314
|
-
share_examples_for 'div.admin-section-header > div.actions > h4 with HELP' do
|
315
|
-
it "should have div.admin-section-header > div.actions > h4 with HELP" do
|
316
|
-
body.should have_tag('div.admin-section-header > div.actions > h4') do |h4|
|
317
|
-
h4.inner_text.should match(/\s*HELP$/)
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
|
323
|
-
###### FORMS ########
|
324
|
-
|
325
|
-
share_examples_for 'faux method > input.hidden[@value=put|delete]' do
|
326
|
-
it "should have a faux method input hidden with method = PUT or DELETE" do
|
327
|
-
body.should match(/<input (name="_method"\s*|type="hidden"\s*|value="(put|delete)"\s*){3}>/)
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
|
332
|
-
###### CSS ########
|
333
|
-
|
334
|
-
share_examples_for 'get_all_css_requests("/css")' do
|
335
|
-
|
336
|
-
it_should_behave_like "CSS [screen, print]"
|
337
|
-
|
338
|
-
it_should_behave_like "CSS [ie]"
|
339
|
-
|
340
|
-
end
|
341
|
-
|
342
|
-
share_examples_for 'get_all_css_requests("/css") (NO IE)' do
|
343
|
-
|
344
|
-
it_should_behave_like "CSS [screen, print]"
|
345
|
-
|
346
|
-
end
|
347
|
-
|
348
|
-
share_examples_for 'CSS [screen, print]' do
|
349
|
-
|
350
|
-
describe "CSS - GET /css/screen.css" do
|
351
|
-
|
352
|
-
before(:each) do
|
353
|
-
get("/css/screen.css")
|
354
|
-
end
|
355
|
-
|
356
|
-
it "should return status: 200" do
|
357
|
-
assert response.ok?
|
358
|
-
end
|
359
|
-
|
360
|
-
it "should return 'text/html'" do
|
361
|
-
# response.headers['Content-Type'].should == 'text/css;charset=utf-8'
|
362
|
-
response.headers['Content-Type'].should == 'text/css'
|
363
|
-
end
|
364
|
-
|
365
|
-
describe "the CSS" do
|
366
|
-
|
367
|
-
# it_should_behave_like "debug"
|
368
|
-
|
369
|
-
it "should NOT have a Sass::SyntaxError" do
|
370
|
-
body.should_not match(/Sass::SyntaxError/)
|
371
|
-
end
|
372
|
-
|
373
|
-
# TODO:: Need to write further tests here
|
374
|
-
# it "should have further tests"
|
375
|
-
|
376
|
-
end #/ the CSS
|
377
|
-
|
378
|
-
end #/CSS - GET /css/screen.css
|
379
|
-
|
380
|
-
describe "CSS - GET /css/print.css" do
|
381
|
-
|
382
|
-
before(:each) do
|
383
|
-
get("/css/print.css")
|
384
|
-
end
|
385
|
-
|
386
|
-
it "should return status: 200" do
|
387
|
-
assert response.ok?
|
388
|
-
end
|
389
|
-
|
390
|
-
it "should return 'text/html'" do
|
391
|
-
# response.headers['Content-Type'].should == 'text/css;charset=utf-8'
|
392
|
-
response.headers['Content-Type'].should == 'text/css'
|
393
|
-
end
|
394
|
-
|
395
|
-
describe "the CSS" do
|
396
|
-
|
397
|
-
# it_should_behave_like "debug"
|
398
|
-
|
399
|
-
it "should NOT have a Sass::SyntaxError" do
|
400
|
-
body.should_not match(/Sass::SyntaxError/)
|
401
|
-
end
|
402
|
-
|
403
|
-
# TODO:: Need to write further tests here
|
404
|
-
# it "should have further tests"
|
405
|
-
|
406
|
-
end #/ the CSS
|
407
|
-
|
408
|
-
end #/CSS - GET /css/print.css
|
409
|
-
|
410
|
-
end
|
411
|
-
|
412
|
-
share_examples_for 'CSS [ie]' do
|
413
|
-
|
414
|
-
describe "CSS - GET /css/ie.css" do
|
415
|
-
|
416
|
-
before(:each) do
|
417
|
-
get("/css/ie.css")
|
418
|
-
end
|
419
|
-
|
420
|
-
it "should return status: 200" do
|
421
|
-
assert response.ok?
|
422
|
-
end
|
423
|
-
|
424
|
-
it "should return 'text/html'" do
|
425
|
-
# response.headers['Content-Type'].should == 'text/css;charset=utf-8' # tilt version
|
426
|
-
response.headers['Content-Type'].should == 'text/css'
|
427
|
-
end
|
428
|
-
|
429
|
-
describe "the CSS" do
|
430
|
-
|
431
|
-
# it_should_behave_like "debug"
|
432
|
-
|
433
|
-
it "should NOT have a Sass::SyntaxError" do
|
434
|
-
body.should_not match(/Sass::SyntaxError/)
|
435
|
-
end
|
436
|
-
|
437
|
-
# TODO:: Need to write further tests here
|
438
|
-
# it "should have further tests"
|
439
|
-
|
440
|
-
end #/ the CSS
|
441
|
-
|
442
|
-
end #/CSS - GET /css/print.css
|
443
|
-
|
444
|
-
end
|
445
|
-
|
446
|
-
|
447
|
-
end #/module SharedSpecs
|
448
|
-
|
449
|
-
end #/module Tests
|
450
|
-
end #/module Sinatra
|