raccoon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format d
@@ -0,0 +1,22 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - ruby-head
7
+ - jruby-19mode
8
+ - jruby-head
9
+ - rbx-19mode
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ - rvm: jruby-head
14
+ branches:
15
+ only:
16
+ - master
17
+ after_success:
18
+ - cover -report coveralls
19
+ notifications:
20
+ recipients:
21
+ - yuliinfo@gmail.com
22
+
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'activemodel'
7
+ gem 'rspec-rails'
8
+ # gem 'capybara'
9
+ gem 'coveralls', :require => false
10
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 yulii
2
+
3
+ MIT License
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.
@@ -0,0 +1,55 @@
1
+ # Raccoon
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'raccoon'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install raccoon
18
+
19
+ ## Usage
20
+
21
+ ### Setup
22
+ at `spec_helper.rb`
23
+ ```ruby
24
+ Raccoon.configure do |config|
25
+ config.application = MyRailsApp::Application
26
+ config.render_views = true # Default: true
27
+ end
28
+ ```
29
+
30
+ ### Describe Testing Statuses
31
+ ```ruby
32
+ require 'spec_helper'
33
+
34
+ Raccoon::Controller.case do
35
+ get name: :root
36
+ get name: :about
37
+ get name: :terms
38
+
39
+ get name: :user, params: { id: 99999 }, response_code: 404
40
+
41
+ get controller: :profiles, action: :index
42
+
43
+ get controller: :admin, action: :index, response_code: 401
44
+
45
+ end
46
+ ```
47
+
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task :default => :spec
@@ -0,0 +1,48 @@
1
+ #!/bin/sh
2
+ LIB_NAME="raccoon"
3
+ if [ $# -ne 2 ]
4
+ then
5
+ echo "Usage: $0 {version} {target}"
6
+ exit 1
7
+ fi
8
+ GEMSPEC="${LIB_NAME}.gemspec"
9
+ PKG_FILE="${LIB_NAME}-$1.gem"
10
+
11
+ echo "[RUN] gem install"
12
+ bundle install
13
+ echo "[RUN] rake"
14
+ bundle exec rake
15
+
16
+ if [ $? -eq 1 ]
17
+ then
18
+ exit 1
19
+ fi
20
+ echo "[RUN] gem build ${GEMSPEC}"
21
+ gem build ${GEMSPEC}
22
+ if [ $? -eq 1 ]
23
+ then
24
+ exit 1
25
+ fi
26
+
27
+ echo "[RUN] mv ${PKG_FILE} pkg/"
28
+ mv ${PKG_FILE} ./pkg
29
+
30
+ case "$2" in
31
+ "install")
32
+ echo "[RUN] rake install pkg/${PKG_FILE}"
33
+ bundle exec rake install --trace
34
+ ;;
35
+ "deploy")
36
+ echo "[RUN] gem push pkg/${PKG_FILE}"
37
+ gem push pkg/${PKG_FILE}
38
+
39
+ echo "[RUN] git tag -a version-$1"
40
+ git tag -a version-$1 -m ""
41
+ git push --tags
42
+ ;;
43
+ *)
44
+ echo "FATAL: invalid target"
45
+ exit 1
46
+ ;;
47
+ esac
48
+
@@ -0,0 +1,11 @@
1
+ require "raccoon/version"
2
+
3
+ require "raccoon/config"
4
+
5
+ require "raccoon/spec/spec"
6
+ require "raccoon/spec/router"
7
+
8
+ require "raccoon/controller"
9
+
10
+ module Raccoon
11
+ end
@@ -0,0 +1,30 @@
1
+ require 'active_support/configurable'
2
+
3
+ module Raccoon
4
+
5
+ def self.configure(&block)
6
+ yield @config ||= Raccoon::Configuration.new
7
+ end
8
+
9
+ def self.config
10
+ @config
11
+ end
12
+
13
+ class Configuration #:nodoc:
14
+ include ActiveSupport::Configurable
15
+ config_accessor :application, :render_views
16
+
17
+ def param_name
18
+ config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
19
+ end
20
+
21
+ # define param_name writer (copied from AS::Configurable)
22
+ writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
23
+ singleton_class.class_eval writer, __FILE__, line
24
+ class_eval writer, __FILE__, line
25
+ end
26
+
27
+ configure do |config|
28
+ config.render_views = true
29
+ end
30
+ end
@@ -0,0 +1,63 @@
1
+ # coding: UTF-8
2
+ module Raccoon
3
+ class Controller
4
+
5
+ attr_reader :routes
6
+
7
+ def initialize &proc
8
+ instance_eval &proc
9
+ end
10
+
11
+ def add router = nil, &block
12
+ @routes ||= []
13
+ @routes << router if router
14
+ @routes << Router.new(&block) if block_given?
15
+ end
16
+
17
+ [:get, :post, :put, :delete].each do |name|
18
+ define_method name do |args, &proc|
19
+ add do
20
+ method name
21
+ name args[:name] if args[:name]
22
+ controller args[:controller] if args[:controller]
23
+ action args[:action] if args[:action]
24
+ params args[:params] if args[:params]
25
+ response_code args[:response_code] if args[:response_code]
26
+ before args[:before] if args[:before]
27
+ after args[:after] if args[:after]
28
+ end
29
+ end
30
+ end
31
+
32
+ class << self
33
+ def case &block
34
+ new(&block).routes.each do |router|
35
+ describe router.controller_class, type: :controller do
36
+ render_views if ::Raccoon.config.render_views
37
+
38
+ before do
39
+ router.before.call
40
+ end
41
+
42
+ context "when requests #{router.method.to_s.upcase} #{router.controller}##{router.action}" do
43
+ let(:params) { router.params.call }
44
+
45
+ # Check HTTP Response Code
46
+ it "should be #{Rack::Utils::HTTP_STATUS_CODES[router.response_code]}" do
47
+ send(router.method, router.action, params)
48
+ expect(response.response_code).to eq(router.response_code)
49
+ end
50
+ end
51
+
52
+ after do
53
+ router.after.call
54
+ end
55
+
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,50 @@
1
+ # coding: UTF-8
2
+ module Raccoon
3
+ class Router < Spec
4
+ def initialize &proc
5
+ instance_eval &proc
6
+ end
7
+
8
+ [:method, :controller, :action].each do |name|
9
+ define_method name do |value=nil|
10
+ instance_variable_set("@#{name}", value) if value
11
+ instance_variable_get("@#{name}")
12
+ end
13
+ end
14
+
15
+ def name value=nil
16
+ @name unless value
17
+ @name = value.to_s
18
+ ::Raccoon.config.application.routes.routes.each do |route|
19
+ if @name == route.name
20
+ @controller = route.defaults[:controller]
21
+ @action = route.defaults[:action]
22
+ end
23
+ end
24
+ end
25
+
26
+ def params value=nil, &block
27
+ @params ||= Proc.new { {} }
28
+ @params = Proc.new { value } if value
29
+ @params = block if block_given?
30
+ @params
31
+ end
32
+
33
+ def response_code response_code=nil
34
+ @response_code = response_code if response_code
35
+ @response_code ||= 200
36
+ end
37
+
38
+ def controller_class
39
+ return nil unless controller
40
+ clazz = Object
41
+ names = controller.split('/')
42
+ controller = "#{names.pop.capitalize}Controller"
43
+ names.each do |name|
44
+ clazz = clazz.const_get(name.capitalize)
45
+ end
46
+ clazz.const_get(controller)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,13 @@
1
+ module Raccoon
2
+ class Spec
3
+
4
+ [:before, :after].each do |name|
5
+ define_method name do |value=:each,&block|
6
+ instance_variable_set("@#{name}", &block) if block_given?
7
+ instance_variable_get("@#{name}")||Proc.new {}
8
+ end
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ module Raccoon
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'raccoon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "raccoon"
8
+ spec.version = Raccoon::VERSION
9
+ spec.authors = ["yulii"]
10
+ spec.email = ["yuliinfo@gmail.com"]
11
+ spec.description = %q{Scan controllers and views for Ruby on Rails}
12
+ spec.summary = %q{Testing controllers and views}
13
+ spec.homepage = "https://github.com/yulii/raccoon"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'rspec-rails', '~> 2.0'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,41 @@
1
+ require 'action_controller/railtie'
2
+ require 'action_view/railtie'
3
+
4
+ # config
5
+ app = Class.new Rails::Application
6
+ app.config.active_support.deprecation = :log
7
+ app.config.secret_token = "e65e0140352e39703c113b0ce30335e8"
8
+ app.config.generators do |g|
9
+ # g.template_engine :haml
10
+ end
11
+ app.initialize!
12
+
13
+ STATUS_CODES = [200, 401, 404, 500]
14
+ # routing
15
+ app.routes.draw do
16
+
17
+ STATUS_CODES.each do |e|
18
+ get "/respond_#{e}" => "raccoon#respond_#{e}", as: "respond_#{e}"
19
+ end
20
+
21
+ end
22
+
23
+ # controllers
24
+ class ApplicationController < ActionController::Base ; end
25
+
26
+ class RaccoonController < ApplicationController
27
+
28
+ STATUS_CODES.each do |e|
29
+ define_method "respond_#{e}" do
30
+ render status: e, text: e, layout: false
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ # helpers
37
+ Object.const_set(:ApplicationHelper, Module.new)
38
+
39
+ Raccoon.configure do |config|
40
+ config.application = app
41
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ describe Raccoon::Spec do
3
+
4
+ before do
5
+ @object = Raccoon::Spec.new
6
+ end
7
+
8
+ [:before, :after].each do |name|
9
+ it "should be defined `#{name}` method" do
10
+ expect(@object).to respond_to(name)
11
+ end
12
+
13
+ context "when `#{name}` method called" do
14
+ it "should be return a Proc object" do
15
+ expect(@object.send(name)).to be_an_instance_of(Proc)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ # coding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ Raccoon::Controller.case do
5
+ STATUS_CODES.each do |code|
6
+ get name: "respond_#{code}", response_code: code
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'raccoon'
4
+
5
+ require 'fake_rails'
6
+ require 'rspec/rails'
7
+
8
+ #require 'capybara/rails'
9
+ require 'coveralls'
10
+
11
+ Coveralls.wear!('rails')
12
+ RSpec.configure do |config|
13
+ config.mock_with :rspec
14
+ config.expect_with :rspec do |c|
15
+ c.syntax = :expect # disables `should`
16
+ end
17
+ config.include Rails.application.routes.url_helpers
18
+ #config.include Capybara::DSL
19
+ end
20
+ #Capybara.configure do |config|
21
+ # config.match = :prefer_exact
22
+ # config.ignore_hidden_elements = false
23
+ #end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: raccoon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - yulii
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Scan controllers and views for Ruby on Rails
63
+ email:
64
+ - yuliinfo@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .travis.yml
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - build_gem.sh
77
+ - lib/raccoon.rb
78
+ - lib/raccoon/config.rb
79
+ - lib/raccoon/controller.rb
80
+ - lib/raccoon/spec/router.rb
81
+ - lib/raccoon/spec/spec.rb
82
+ - lib/raccoon/version.rb
83
+ - raccoon.gemspec
84
+ - spec/fake_rails.rb
85
+ - spec/raccoon/spec/spec_spec.rb
86
+ - spec/raccoon_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: https://github.com/yulii/raccoon
89
+ licenses:
90
+ - MIT
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.24
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Testing controllers and views
113
+ test_files:
114
+ - spec/fake_rails.rb
115
+ - spec/raccoon/spec/spec_spec.rb
116
+ - spec/raccoon_spec.rb
117
+ - spec/spec_helper.rb