what_the 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/lib/what_the/backbone_helper.rb +19 -0
- data/lib/what_the/constant_helper.rb +18 -0
- data/lib/what_the/given_when_then_helper.rb +36 -0
- data/lib/what_the/route_matcher.rb +31 -0
- data/lib/what_the/rspec_mocks_validation.rb +31 -0
- data/lib/what_the/version.rb +3 -0
- data/lib/what_the.rb +7 -0
- data/what_the.gemspec +24 -0
- metadata +68 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# WHAT THE FOR RSPEC
|
2
|
+
|
3
|
+
what the is a group of rspec support files I find helpful
|
4
|
+
|
5
|
+
Enjoy.
|
6
|
+
|
7
|
+
## SETUP
|
8
|
+
|
9
|
+
### GEMFILE
|
10
|
+
|
11
|
+
In your Gemfile:
|
12
|
+
|
13
|
+
gem 'what_the', '~> 0.0.1'
|
14
|
+
|
15
|
+
### SPEC_HELPER
|
16
|
+
In spec/spec_helper.rb:
|
17
|
+
|
18
|
+
require 'what_the'
|
19
|
+
|
20
|
+
config.include WhatThe::GivenWhenThenHelper, :type => :integration, :example_group => {
|
21
|
+
:file_path => config.escaped_path(%w[spec integration])
|
22
|
+
}
|
23
|
+
|
24
|
+
config.include WhatThe::BackboneHelper, :type => :controller, :example_group => {
|
25
|
+
:file_path => config.escaped_path(%w[spec controllers])
|
26
|
+
}
|
27
|
+
|
28
|
+
## USAGE
|
29
|
+
|
30
|
+
### WhatThe::RouteMatcher
|
31
|
+
|
32
|
+
### WhatThe::RSpecMocksValidation
|
33
|
+
|
34
|
+
### WhatThe::GivenWhenThenHelper
|
35
|
+
|
36
|
+
### WhatThe::BackboneHelper
|
37
|
+
|
38
|
+
### WhatThe::ConstantHelper
|
39
|
+
|
40
|
+
|
41
|
+
----
|
42
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module WhatThe
|
2
|
+
module BackboneHelper
|
3
|
+
def response_json
|
4
|
+
JSON.parse(response.body).with_indifferent_access
|
5
|
+
end
|
6
|
+
|
7
|
+
def response_json_redirect
|
8
|
+
response_json[:redirect]
|
9
|
+
end
|
10
|
+
|
11
|
+
def response_json_success
|
12
|
+
response_json[:importance] == "success"
|
13
|
+
end
|
14
|
+
|
15
|
+
def response_json_error
|
16
|
+
response_json[:importance] == "error"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# see http://stackoverflow.com/questions/1698335/can-i-use-rspec-mocks-to-stub-out-version-constants
|
2
|
+
class Object
|
3
|
+
def self.with_constants(constants, &block)
|
4
|
+
saved_constants = {}
|
5
|
+
constants.each do |constant, val|
|
6
|
+
saved_constants[ constant ] = const_get( constant )
|
7
|
+
Kernel::silence_warnings { const_set( constant, val ) }
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
block.call
|
12
|
+
ensure
|
13
|
+
constants.each do |constant, val|
|
14
|
+
Kernel::silence_warnings { const_set( constant, saved_constants[ constant ] ) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module WhatThe
|
2
|
+
module GivenWhenThenHelper
|
3
|
+
def self.included(base)
|
4
|
+
class << base
|
5
|
+
def Context(*args, &block)
|
6
|
+
args.unshift("[context #{args.shift}]")
|
7
|
+
describe(*args, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def Given(*args, &block)
|
11
|
+
args.unshift("given #{args.shift}")
|
12
|
+
describe(*args, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def When(*args, &block)
|
16
|
+
args.unshift("when #{args.shift}")
|
17
|
+
describe(*args, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec::Core::ExampleGroup.class_eval do
|
22
|
+
def self.Then(*args, &block)
|
23
|
+
it(*(["then #{args.shift}"] << args), &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.And_(*args, &block)
|
27
|
+
it(*(["and #{args.shift}"] << args), &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Object
|
35
|
+
alias_method :Scenario, :describe
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module WhatThe
|
2
|
+
module RouteMatcher
|
3
|
+
class Matcher
|
4
|
+
attr_reader :route_controller, :route_params, :with_params
|
5
|
+
def initialize(route_controller, params = {})
|
6
|
+
@route_controller = route_controller.to_s
|
7
|
+
@route_params = params
|
8
|
+
@with_params = params.map{|key, value| ":#{key} => #{value}"}.join(' ')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def match_controller(route_controller, params = {}, &block)
|
13
|
+
@route_matcher = RouteMatcher::Matcher.new(route_controller, params)
|
14
|
+
yield
|
15
|
+
@route_matcher = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def with_route(html_method, routes)
|
19
|
+
matcher = @route_matcher
|
20
|
+
|
21
|
+
routes.each do |path, method|
|
22
|
+
it "routes #{html_method} #{path} to #{matcher.route_controller}##{method} #{matcher.with_params}" do
|
23
|
+
{ html_method => "#{path}" }.should route_to(
|
24
|
+
{:controller => matcher.route_controller,
|
25
|
+
:action => method.to_s }.merge(matcher.route_params)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rspec/mocks'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Mocks
|
5
|
+
module Methods
|
6
|
+
def validate_method_exists(method_name)
|
7
|
+
return if self.is_a?(RSpec::Mocks::Mock)
|
8
|
+
raise "Attempted to stub #{method_name} which doesn't exist on #{self}" unless self.respond_to?(method_name.to_sym)
|
9
|
+
end
|
10
|
+
|
11
|
+
def should_receive_with_validation(sym, opts={}, &block)
|
12
|
+
validate_method_exists(sym)
|
13
|
+
should_receive_without_validation(sym, opts, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def should_not_receive_with_validation(sym, &block)
|
17
|
+
validate_method_exists(sym)
|
18
|
+
should_not_receive_without_validation(sym, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def stub_with_validation(sym_or_hash, opts={}, &block)
|
22
|
+
validate_method_exists(sym_or_hash) unless sym_or_hash.instance_of?(Hash)
|
23
|
+
stub_without_validation(sym_or_hash, opts, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
alias_method_chain :should_receive, :validation
|
27
|
+
alias_method_chain :should_not_receive, :validation
|
28
|
+
alias_method_chain :stub, :validation
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/what_the.rb
ADDED
data/what_the.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "what_the/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "what_the"
|
7
|
+
s.version = WhatThe::VERSION
|
8
|
+
s.authors = ["Chris Douglas"]
|
9
|
+
s.email = ["dougo.chris@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/dougochris/what_the"
|
11
|
+
s.summary = %q{RSpec Support files}
|
12
|
+
s.description = %q{RSpec Support files - Given-When-Then, and more}
|
13
|
+
|
14
|
+
s.rubyforge_project = "what_the"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: what_the
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Douglas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-16 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70125102092300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70125102092300
|
25
|
+
description: RSpec Support files - Given-When-Then, and more
|
26
|
+
email:
|
27
|
+
- dougo.chris@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- lib/what_the.rb
|
37
|
+
- lib/what_the/backbone_helper.rb
|
38
|
+
- lib/what_the/constant_helper.rb
|
39
|
+
- lib/what_the/given_when_then_helper.rb
|
40
|
+
- lib/what_the/route_matcher.rb
|
41
|
+
- lib/what_the/rspec_mocks_validation.rb
|
42
|
+
- lib/what_the/version.rb
|
43
|
+
- what_the.gemspec
|
44
|
+
homepage: https://github.com/dougochris/what_the
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project: what_the
|
64
|
+
rubygems_version: 1.8.10
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: RSpec Support files
|
68
|
+
test_files: []
|