blindfold 0.0.2

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 ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ pkg
3
+ rdoc
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 James Bunch
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.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ = Blindfold
2
+
3
+ API/XML focused integration testing for Rack apps
4
+
5
+ == What is Blindfold?
6
+
7
+ Blindfold brings together RSpec, Rack::Test, and Machinist for the
8
+ express purpose of providing integration test coverage for web based
9
+ API services (especially those with an XML response).
10
+
11
+ == Usage
12
+
13
+ $ gem install blindfold
14
+
15
+ $ blindfold /path/to/blindfold_test.rb
16
+
17
+ == Configuration
18
+
19
+ (Coming)
20
+
21
+ == Resources
22
+
23
+ - Source: http://github.com/fallwith/blindfold
24
+
25
+ == Credits
26
+
27
+ Blindfold was created by James Bunch (fallwith) and improved by the SCEA SDOD team
28
+
29
+ Copyright (c) 2010 James Bunch, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/rdoctask'
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Default: run specs.'
7
+ task :default => :spec
8
+
9
+ desc 'Run specs to test blindfold.'
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.pattern = FileList["spec/**/*_spec.rb"]
12
+ end
13
+
14
+ desc 'Generate documentation for blindfold.'
15
+ Rake::RDocTask.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Blindfold'
18
+ rdoc.options << '--line-numbers' << '--inline-source'
19
+ rdoc.options << '--charset' << 'utf-8'
20
+ rdoc.rdoc_files.include('README.rdoc')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
data/bin/blindfold ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require 'isolate/now'
3
+ require 'blindfold'
4
+
5
+ opts = {:config_dir => File.expand_path(File.dirname(__FILE__) + '/../tests/config'),
6
+ :rails_root => File.expand_path(File.dirname(__FILE__) + '/..'),
7
+ :boot_redis => true}
8
+
9
+ Launcher.new(opts).run(ARGV)
data/blindfold.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'blindfold'
5
+ gem.version = '0.0.2'
6
+ gem.date = %{2010-06-24}
7
+
8
+ gem.authors = ["James Bunch (fallwith)"]
9
+ gem.email = nil
10
+ gem.homepage = 'http://github.com/fallwith/blindfold'
11
+
12
+ gem.summary = "API/XML focused integration testing for Rack apps"
13
+ gem.description = "Blindfold brings together RSpec, Rack::Test, and Machinist for the
14
+ express purpose of providing integration test coverage for web based
15
+ API services (especially those with an XML response)."
16
+
17
+ gem.files = [
18
+ '.gitignore',
19
+ 'bin/blindfold',
20
+ 'blindfold.gemspec',
21
+ 'config/spec.opts',
22
+ 'init.rb',
23
+ 'lib/blindfold/connection.rb',
24
+ 'lib/blindfold/helpers/date.rb',
25
+ 'lib/blindfold/helpers/db.rb',
26
+ 'lib/blindfold/helpers.rb',
27
+ 'lib/blindfold/launcher.rb',
28
+ 'lib/blindfold/spec/matchers/be_an_ip_address.rb',
29
+ 'lib/blindfold/spec/matchers/be_an_iso_date.rb',
30
+ 'lib/blindfold/spec/matchers/be_ok.rb',
31
+ 'lib/blindfold/spec/monkey.rb',
32
+ 'lib/blindfold/spec.rb',
33
+ 'lib/blindfold/xml/monkey.rb',
34
+ 'lib/blindfold/xml.rb',
35
+ 'lib/blindfold.rb',
36
+ 'MIT-LICENSE',
37
+ 'Rakefile',
38
+ 'README.rdoc',
39
+ 'VERSION'
40
+ ]
41
+
42
+ gem.add_dependency('rspec', '>= 1.3.0')
43
+ gem.add_dependency('rack-test', '>= 0.5.4')
44
+ gem.add_dependency('machinist', '>= 1.0.6')
45
+ gem.add_dependency('forgery', '>= 0.3.4')
46
+ end
data/config/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ # Placeholder for Rails' benefit
@@ -0,0 +1,60 @@
1
+ class Connection
2
+ include Rack::Test::Methods
3
+
4
+ def initialize(args={})
5
+ perform_pre_flight_check
6
+ log_in unless args.has_key?(:logged_in) && !args[:logged_in]
7
+ end
8
+
9
+ def log_in
10
+ # Define for your app's process of logging in
11
+ end
12
+
13
+ def call(name, params={})
14
+ method, url = resolve(name)
15
+ process_request method, url, params
16
+ @cookie_session_id = last_response.headers['Set-Cookie']
17
+ end
18
+
19
+ def response
20
+ last_response
21
+ end
22
+
23
+ def xml
24
+ Nokogiri::XML(last_response.body)
25
+ end
26
+
27
+ private
28
+
29
+ def perform_pre_flight_check
30
+ # Define for your app's prerequisite checks (connection to db, etc.)
31
+ end
32
+
33
+ def app
34
+ ActionController::Dispatcher.new # For Rails
35
+ end
36
+
37
+ def process_request(method, url, params)
38
+ env_vars = {} # Define your app's required environment vars
39
+
40
+ header('Cookie', @cookie_session_id) if @cookie_session_id
41
+
42
+ case method.downcase.to_s
43
+ when 'get'
44
+ get url, params, env_vars
45
+ when 'post'
46
+ post url, params, env_vars
47
+ when 'put'
48
+ put url, params, env_vars
49
+ when 'delete'
50
+ delete url, params, env_vars
51
+ else
52
+ raise "Unsupported method '#{method}'!"
53
+ end
54
+ end
55
+
56
+ def resolve(service)
57
+ # Define for your app. Return a URL and method for the given service nickname
58
+ ['get', service]
59
+ end
60
+ end
@@ -0,0 +1,7 @@
1
+ module HelperMethods
2
+ # Inspired by random_data's date method, http://github.com/tomharris/random_data
3
+ def random_datetime(args={:dayrange => 7, :force_future => false})
4
+ offset = args[:force_future] ? rand(args[:dayrange]) : (rand(args[:dayrange]*2)-args[:dayrange])
5
+ Time.now + (offset * 24 * 60 * 60)
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module HelperMethods
2
+ def wipe(name)
3
+ klass = name.to_s.singularize.camelize.constantize
4
+ klass.delete_all
5
+ end
6
+
7
+ def spawn(name, args={})
8
+ klass = name.to_s.singularize.camelize.constantize
9
+ klass.make(args)
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'helpers','**','*.rb'))].each {|f| require f}
@@ -0,0 +1,97 @@
1
+ class Launcher
2
+ SPEC_OPTS_FILE = 'spec.opts'
3
+ BLUEPRINTS_DIR = 'blueprints' # lives within config_dir
4
+ MATCHERS_DIR = 'matchers' # lives within config_dir
5
+ HELPERS_DIR = 'helpers' # lives within config_dir
6
+
7
+ def initialize(args={})
8
+ Blindfold.config_dir = args[:config_dir] if args.has_key?(:config_dir)
9
+ Blindfold.rails_root = args[:rails_root] if args.has_key?(:rails_root)
10
+ Blindfold.boot_redis = args[:boot_redis] if args.has_key?(:boot_redis)
11
+ end
12
+
13
+ def run(arguments)
14
+ start_redis if Blindfold.boot_redis
15
+ init_rails if Blindfold.rails_root
16
+ init_helpers
17
+ init_blueprints
18
+ init_matchers
19
+ run_spec(arguments)
20
+ stop_redis if Blindfold.boot_redis
21
+ end
22
+
23
+ private
24
+
25
+ def init_helpers
26
+ helpers_dir = File.join(Blindfold.config_dir, HELPERS_DIR)
27
+ if Dir.exists?(helpers_dir)
28
+ Dir[File.join(helpers_dir,'**','*.rb')].each {|f| load f}
29
+ end
30
+ end
31
+
32
+ def init_blueprints
33
+ # Introduce all helper methods to Machinist
34
+ Machinist::Lathe.send :include, HelperMethods
35
+ # Load up all blueprints
36
+ blueprints_dir = File.join(Blindfold.config_dir, BLUEPRINTS_DIR)
37
+ if Dir.exists?(blueprints_dir)
38
+ Dir[File.join(blueprints_dir,'**','*_blueprint.rb')].each {|f| load f}
39
+ end
40
+ end
41
+
42
+ def init_matchers
43
+ matchers_dir = File.join(Blindfold.config_dir, MATCHERS_DIR)
44
+ if Dir.exists?(matchers_dir)
45
+ Dir[File.join(matchers_dir,'**','*.rb')].each {|f| load f}
46
+ end
47
+ end
48
+
49
+ # Light up Spec::Runner
50
+ def run_spec(args)
51
+ # Introduce Rack::Test to RSpec
52
+ Spec::Runner.configure do |config|
53
+ config.include Rack::Test::Methods
54
+ end
55
+
56
+ # Introduce all helper methods to RSpec
57
+ Spec::Runner.configuration.include(HelperMethods)
58
+
59
+ # Specify which spec.opts file to use
60
+ spec_opts = File.join(Blindfold.config_dir, SPEC_OPTS_FILE)
61
+ if File.exists?(spec_opts)
62
+ args << '-O' << spec_opts
63
+ end
64
+
65
+ ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(args, STDERR, STDOUT))
66
+ end
67
+
68
+ def init_rails
69
+ require File.join(Blindfold.rails_root, 'config', 'environment') if Blindfold.rails_root
70
+ end
71
+
72
+ def redis_pid
73
+ `ps acx|grep redis-server|awk {'print $1'}`.chomp
74
+ end
75
+
76
+ # Start redis if necessary and requested
77
+ def start_redis
78
+ return if RUBY_PLATFORM =~ /mswin|mingw/
79
+ if redis_pid == ''
80
+ redis_binary = `which redis-server`.chomp
81
+ if redis_binary.chomp != ''
82
+ spawn "echo 'daemonize yes'|#{redis_binary} -"
83
+ puts "Started redis-server [#{redis_pid}]"
84
+ @started_redis = true
85
+ end
86
+ end
87
+ end
88
+
89
+ # Stop redis if this class started it earlier
90
+ def stop_redis
91
+ return unless @started_redis
92
+ return if RUBY_PLATFORM =~ /mswin|mingw/
93
+ print 'Stopping redis-server...'
94
+ `killall redis-server`
95
+ puts 'Done'
96
+ end
97
+ end
@@ -0,0 +1,14 @@
1
+ Spec::Matchers.define :be_an_ip_address do
2
+ match do |ip_address|
3
+ ip_address.to_s =~ /^(?:(?:\d+\.){3}|(?:\d+\.){5})\d+$/
4
+ end
5
+ failure_message_for_should do |ip_address|
6
+ "expected '#{ip_address}' to be a valid IP Address format (v4 or v6)"
7
+ end
8
+ failure_message_for_should_not do |ip_address|
9
+ "expected '#{ip_address}' to not be a valid IP Address format (v4 or v6)"
10
+ end
11
+ description do
12
+ "expected an IP Address to be in a valid format (v4 or v6)"
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ Spec::Matchers.define :be_an_iso_date do
2
+ pattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[-+]\d{2}:\d{2}$/
3
+ match do |date|
4
+ date.to_s =~ pattern
5
+ end
6
+ failure_message_for_should do |date|
7
+ "expected '#{date}' to be an ISO 8601 formatted date string (#{pattern})"
8
+ end
9
+ failure_message_for_should_not do |date|
10
+ "expected '#{date}' to not be in ISO 8601 format (#{pattern})"
11
+ end
12
+ description do
13
+ "expected a date string to be in ISO 8601 format"
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ module Spec
2
+ module Matchers
3
+ # This drills down into the .status and .result objects of
4
+ # response to see whether they both have successful states.
5
+ # This is needed because a param validation error may throw
6
+ # 200 Ok but -5 Invalid param (by design)
7
+ def be_ok
8
+ Matcher.new :be_ok do
9
+ match do |response|
10
+ status_element = Nokogiri::XML(response.body).xpath('/result/status').first
11
+ status_id = status_element ? status_element.xpath('id').first.text : nil
12
+ response.status == 200 && status_id == '0'
13
+ end
14
+
15
+ failure_message_for_should do |response|
16
+ status_element = Nokogiri::XML(response.body).xpath('/result/status').first
17
+ if status_element
18
+ status_id = status_element.xpath('id').first.text
19
+ status_message = status_element.xpath('message').first.text
20
+ text = "#{status_id}: #{status_message}"
21
+ else
22
+ text = response.body
23
+ end
24
+ <<-MESSAGE
25
+ expected HTTP 200 / 0: Successful Completion
26
+ got HTTP #{response.status} / #{text}
27
+ MESSAGE
28
+ end
29
+
30
+ failure_message_for_should_not do |response|
31
+ status_element = Nokogiri::XML(response.body).xpath('/result/status').first
32
+ if status_element
33
+ status_id = status_element.xpath('id').first.text
34
+ status_message = status_element.xpath('message').first.text
35
+ text = "#{status_id}: #{status_message}"
36
+ else
37
+ text = response.body
38
+ end
39
+ <<-MESSAGE
40
+ expected not HTTP 200 / 0: Successful Completion
41
+ got HTTP #{response.status} / #{text}
42
+ MESSAGE
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,14 @@
1
+ module Spec::Example::ExampleGroupMethods
2
+ alias scenario example # Steak
3
+ alias background before # Steak
4
+ def prepare(&block)
5
+ before :all, &block
6
+ end
7
+ def cleanup(&block)
8
+ after :all, &block
9
+ end
10
+ end
11
+
12
+ module Spec::DSL::Main
13
+ alias feature describe # Steak
14
+ end
@@ -0,0 +1 @@
1
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'spec','**','*.rb'))].each {|f| require f}
@@ -0,0 +1,14 @@
1
+ module Nokogiri::XML
2
+ class Document
3
+ def elements(name)
4
+ xpath("//#{name}")
5
+ end
6
+ end
7
+ class NodeSet
8
+ def with_attributes(attributes)
9
+ # TODO: refactor to remove eval
10
+ conditions = attributes.collect{|k,v| "e['#{k.to_s}'] == '#{v.to_s}'"}.join(' && ')
11
+ eval "select{|e| #{conditions}}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'xml','**','*.rb'))].each {|f| require f}
data/lib/blindfold.rb ADDED
@@ -0,0 +1,22 @@
1
+ class Blindfold
2
+ require 'spec'
3
+ require 'machinist/active_record'
4
+ require 'sham'
5
+ require 'forgery'
6
+ require 'rack/test'
7
+ require 'nokogiri'
8
+
9
+ require 'blindfold/launcher'
10
+ require 'blindfold/connection'
11
+ require 'blindfold/spec'
12
+ require 'blindfold/xml'
13
+ require 'blindfold/helpers'
14
+
15
+ mattr_accessor :config_dir
16
+ mattr_accessor :rails_root
17
+ mattr_accessor :boot_redis
18
+
19
+ @@config_dir = File.dirname(__FILE__) + '/../config'
20
+ @@rails_root = nil
21
+ @@boot_redis = false
22
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blindfold
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - James Bunch (fallwith)
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-24 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 1
32
+ - 3
33
+ - 0
34
+ version: 1.3.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rack-test
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ - 5
49
+ - 4
50
+ version: 0.5.4
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: machinist
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 27
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 6
66
+ version: 1.0.6
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: forgery
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 27
78
+ segments:
79
+ - 0
80
+ - 3
81
+ - 4
82
+ version: 0.3.4
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ description: |-
86
+ Blindfold brings together RSpec, Rack::Test, and Machinist for the
87
+ express purpose of providing integration test coverage for web based
88
+ API services (especially those with an XML response).
89
+ email:
90
+ executables: []
91
+
92
+ extensions: []
93
+
94
+ extra_rdoc_files: []
95
+
96
+ files:
97
+ - .gitignore
98
+ - bin/blindfold
99
+ - blindfold.gemspec
100
+ - config/spec.opts
101
+ - init.rb
102
+ - lib/blindfold/connection.rb
103
+ - lib/blindfold/helpers/date.rb
104
+ - lib/blindfold/helpers/db.rb
105
+ - lib/blindfold/helpers.rb
106
+ - lib/blindfold/launcher.rb
107
+ - lib/blindfold/spec/matchers/be_an_ip_address.rb
108
+ - lib/blindfold/spec/matchers/be_an_iso_date.rb
109
+ - lib/blindfold/spec/matchers/be_ok.rb
110
+ - lib/blindfold/spec/monkey.rb
111
+ - lib/blindfold/spec.rb
112
+ - lib/blindfold/xml/monkey.rb
113
+ - lib/blindfold/xml.rb
114
+ - lib/blindfold.rb
115
+ - MIT-LICENSE
116
+ - Rakefile
117
+ - README.rdoc
118
+ - VERSION
119
+ has_rdoc: true
120
+ homepage: http://github.com/fallwith/blindfold
121
+ licenses: []
122
+
123
+ post_install_message:
124
+ rdoc_options: []
125
+
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 3
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 3
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ requirements: []
147
+
148
+ rubyforge_project:
149
+ rubygems_version: 1.3.7
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: API/XML focused integration testing for Rack apps
153
+ test_files: []
154
+