rspec-sinatra 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1829f46dbcac8ce684316d12fcc52713115e13c
4
+ data.tar.gz: 6fae74898261085dbeb0403bb6d82ffc6276585c
5
+ SHA512:
6
+ metadata.gz: 0f0a2b56fa1a18dd4e4ea4a61ecc4105afd8127c70a112a50997e2ae8773784205246b20a4e17731fe5f45697a2166439638c2447251e46a0bd2e262587ea23b
7
+ data.tar.gz: dd2c69d9adf15abf3b77d939a631274b0122094b29beab3ffa162808cadbecc81d33c64c7c74bd5d5fa44542599b68e92496ed2da27f513f4bf69aa6251508d9
@@ -0,0 +1,5 @@
1
+ ChangeLog
2
+ =========
3
+
4
+ # 0.1.0
5
+ * Initial release.
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ rspec-sinatra license
2
+ ========================
3
+ Copyright (c) 2014 Sam Joseph <tansaku@gmail.com>
4
+
5
+ Permission to use, copy, modify, and distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,46 @@
1
+ rspec-sinatra
2
+ ================
3
+
4
+ # Description
5
+
6
+ This little gem will help you to initialize a rspec environment for a sinatra
7
+ application. It will generate the required files from templates.
8
+
9
+ For now it's generating a `spec_helper.rb` that is using [capybara](http://github.com/jnicklas/capybara). More options might be added later.
10
+
11
+ The entire concept is inspired and largely copied from bernd's [cucumber-sinatra gem](https://github.com/bernd/cucumber-sinatra)
12
+
13
+ # Installation
14
+
15
+ It's available as a gem that can be installed with the following command.
16
+
17
+ gem install rspec-sinatra
18
+
19
+ To use the generated templates without any modification, you'll have to install the capybara (at least v1.0.0) gem as well.
20
+
21
+ # Usage
22
+
23
+ To initialize the rspec environment, just execute `rspec-sinatra` like this:
24
+
25
+ # rspec-sinatra init MyApp lib/my_app.rb
26
+ [ADDED] spec/spec_helper.rb
27
+ #
28
+
29
+ * The first argument is the class name of your application.
30
+ * The second argument is the path to the application file that should be required.
31
+
32
+ Using the `--app` option with `init` will also generate the given application file
33
+ and a working `config.ru`.
34
+
35
+ # rspec-sinatra init --app MyApp lib/my_app.rb
36
+ [ADDED] spec/spec_helper.rb
37
+ [ADDED] lib/my_app.rb
38
+ [ADDED] config.ru
39
+ #
40
+
41
+ # Copyright
42
+
43
+
44
+ This code is licensed under a BSD license.
45
+
46
+ See the LICENSE file for a copy of the license.
@@ -0,0 +1,148 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def name_path
16
+ name.gsub('-', '/')
17
+ end
18
+
19
+ def version
20
+ line = File.read("lib/#{name_path}.rb")[/^\s*VERSION\s*=\s*.*/]
21
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
22
+ end
23
+
24
+ def date
25
+ Date.today.to_s
26
+ end
27
+
28
+ def rubyforge_project
29
+ name
30
+ end
31
+
32
+ def gemspec_file
33
+ "#{name}.gemspec"
34
+ end
35
+
36
+ def gem_file
37
+ "#{name}-#{version}.gem"
38
+ end
39
+
40
+ def replace_header(head, header_name)
41
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
42
+ end
43
+
44
+ #############################################################################
45
+ #
46
+ # Standard tasks
47
+ #
48
+ #############################################################################
49
+
50
+ task :default => :test
51
+
52
+ require 'rake/testtask'
53
+ Rake::TestTask.new(:test) do |test|
54
+ test.libs << 'lib' << 'test'
55
+ test.pattern = 'test/**/test_*.rb'
56
+ test.verbose = true
57
+ end
58
+
59
+ desc "Generate RCov test coverage and open in your browser"
60
+ task :coverage do
61
+ require 'rcov'
62
+ sh "rm -fr coverage"
63
+ sh "rcov test/test_*.rb"
64
+ sh "open coverage/index.html"
65
+ end
66
+
67
+ require 'rake/rdoctask'
68
+ Rake::RDocTask.new do |rdoc|
69
+ rdoc.rdoc_dir = 'rdoc'
70
+ rdoc.title = "#{name} #{version}"
71
+ rdoc.rdoc_files.include('README*')
72
+ rdoc.rdoc_files.include('lib/**/*.rb')
73
+ end
74
+
75
+ desc "Open an irb session preloaded with this library"
76
+ task :console do
77
+ sh "irb -rubygems -r ./lib/#{name_path}.rb"
78
+ end
79
+
80
+ #############################################################################
81
+ #
82
+ # Custom tasks (add your own tasks here)
83
+ #
84
+ #############################################################################
85
+
86
+
87
+
88
+ #############################################################################
89
+ #
90
+ # Packaging tasks
91
+ #
92
+ #############################################################################
93
+
94
+ desc "Update gemspec, build gem, commit with 'Release x.x.x', create tag, push to github and gemcutter"
95
+ task :release => :build do
96
+ unless `git branch` =~ /^\* master$/
97
+ puts "You must be on the master branch to release!"
98
+ exit!
99
+ end
100
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
101
+ sh "git tag v#{version}"
102
+ sh "git push origin master"
103
+ sh "git push origin tag v#{version}"
104
+ sh "gem push pkg/#{name}-#{version}.gem"
105
+ end
106
+
107
+ desc "Update gemspec and build gem"
108
+ task :build => :gemspec do
109
+ sh "mkdir -p pkg"
110
+ sh "gem build #{gemspec_file}"
111
+ sh "mv #{gem_file} pkg"
112
+ end
113
+
114
+ desc "Update gemspec with the latest version and file list"
115
+ task :gemspec => :validate do
116
+ # read spec file and split out manifest section
117
+ spec = File.read(gemspec_file)
118
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
119
+
120
+ # replace name version and date
121
+ replace_header(head, :name)
122
+ replace_header(head, :version)
123
+ replace_header(head, :date)
124
+ #comment this out if your rubyforge_project has a different name
125
+ replace_header(head, :rubyforge_project)
126
+
127
+ # determine file list from git ls-files
128
+ files = `git ls-files`.
129
+ split("\n").
130
+ sort.
131
+ reject { |file| file =~ /^\./ }.
132
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
133
+ map { |file| " #{file}" }.
134
+ join("\n")
135
+
136
+ # piece file back together and write
137
+ manifest = " s.files = %w[\n#{files}\n ]\n"
138
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
139
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
140
+ puts "Updated #{gemspec_file}"
141
+ end
142
+
143
+ task :validate do
144
+ unless Dir['VERSION*'].empty?
145
+ puts "A `VERSION` file at root level violates Gem best practices."
146
+ exit!
147
+ end
148
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rspec/sinatra'
5
+ require 'rspec/sinatra/generators'
6
+
7
+ RSpec::Sinatra::Generators.run_cli Dir.pwd, File.basename(__FILE__), RSpec::Sinatra::VERSION, ARGV
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module Sinatra
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,37 @@
1
+ require 'templater'
2
+
3
+ module RSpec
4
+ module Sinatra
5
+ module Generators
6
+ extend Templater::Manifold
7
+
8
+ class InitGenerator < Templater::Generator
9
+ def self.source_root
10
+ File.join(File.dirname(__FILE__), 'templates')
11
+ end
12
+
13
+ desc <<-DESC
14
+ Initialize an rspec environment for a sinatra application.
15
+ rspec-sinatra MyApp lib/myapp.rb
16
+ DESC
17
+
18
+ first_argument :app_class, :required => true, :desc => 'Application class'
19
+ second_argument :app_file, :required => true, :desc => 'Application file'
20
+
21
+ option :app, :as => :boolean, :default => false, :desc => 'Create the application files as well.'
22
+
23
+ template :spec_helper, 'spec/spec_helper.rb'
24
+
25
+ template :app_file, 'app.rbt', '%app_file_path%', :app => true
26
+ template :rackup_file, 'config.ru', 'config.ru', :app => true
27
+
28
+ def app_file_path
29
+ app_file
30
+ end
31
+ end
32
+
33
+ desc "Generators to simplify the usage of rspec with sinatra."
34
+ add :init, InitGenerator
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ require 'sinatra/base'
2
+
3
+ class <%= app_class -%> < Sinatra::Base
4
+ get '/' do
5
+ 'Hello <%= app_class -%>!'
6
+ end
7
+
8
+ # start the server if ruby file executed directly
9
+ run! if app_file == $0
10
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require File.join(File.dirname(__FILE__), '<%= app_file -%>')
3
+
4
+ run <%= app_class -%>
@@ -0,0 +1,104 @@
1
+ # Generated by rspec-sinatra. (<%= Time.now %>)
2
+
3
+ ENV['RACK_ENV'] = 'test'
4
+
5
+ require File.join(File.dirname(__FILE__), '..', '<%= app_file -%>')
6
+
7
+ require 'capybara'
8
+ require 'capybara/rspec'
9
+ require 'rspec'
10
+
11
+ Capybara.app = <%= app_class -%>
12
+
13
+ # hmm - should be generated by `rspec --init` directly rather than copy paste ...
14
+
15
+ # This file was generated by the `rspec --init` command. Conventionally, all
16
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
17
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
18
+ # file to always be loaded, without a need to explicitly require it in any files.
19
+ #
20
+ # Given that it is always loaded, you are encouraged to keep this file as
21
+ # light-weight as possible. Requiring heavyweight dependencies from this file
22
+ # will add to the boot time of your test suite on EVERY test run, even for an
23
+ # individual file that may not need all of that loaded. Instead, consider making
24
+ # a separate helper file that requires the additional dependencies and performs
25
+ # the additional setup, and require it from the spec files that actually need it.
26
+ #
27
+ # The `.rspec` file also contains a few flags that are not defaults but that
28
+ # users commonly want.
29
+ #
30
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
31
+ RSpec.configure do |config|
32
+ config.include Capybara::DSL
33
+ # rspec-expectations config goes here. You can use an alternate
34
+ # assertion/expectation library such as wrong or the stdlib/minitest
35
+ # assertions if you prefer.
36
+ config.expect_with :rspec do |expectations|
37
+ # This option will default to `true` in RSpec 4. It makes the `description`
38
+ # and `failure_message` of custom matchers include text for helper methods
39
+ # defined using `chain`, e.g.:
40
+ # be_bigger_than(2).and_smaller_than(4).description
41
+ # # => "be bigger than 2 and smaller than 4"
42
+ # ...rather than:
43
+ # # => "be bigger than 2"
44
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
45
+ end
46
+
47
+ # rspec-mocks config goes here. You can use an alternate test double
48
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
49
+ config.mock_with :rspec do |mocks|
50
+ # Prevents you from mocking or stubbing a method that does not exist on
51
+ # a real object. This is generally recommended, and will default to
52
+ # `true` in RSpec 4.
53
+ mocks.verify_partial_doubles = true
54
+ end
55
+
56
+ # The settings below are suggested to provide a good initial experience
57
+ # with RSpec, but feel free to customize to your heart's content.
58
+ =begin
59
+ # These two settings work together to allow you to limit a spec run
60
+ # to individual examples or groups you care about by tagging them with
61
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
62
+ # get run.
63
+ config.filter_run :focus
64
+ config.run_all_when_everything_filtered = true
65
+
66
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
67
+ # For more details, see:
68
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
69
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
70
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
71
+ config.disable_monkey_patching!
72
+
73
+ # This setting enables warnings. It's recommended, but in some cases may
74
+ # be too noisy due to issues in dependencies.
75
+ config.warnings = true
76
+
77
+ # Many RSpec users commonly either run the entire suite or an individual
78
+ # file, and it's useful to allow more verbose output when running an
79
+ # individual spec file.
80
+ if config.files_to_run.one?
81
+ # Use the documentation formatter for detailed output,
82
+ # unless a formatter has already been configured
83
+ # (e.g. via a command-line flag).
84
+ config.default_formatter = 'doc'
85
+ end
86
+
87
+ # Print the 10 slowest examples and example groups at the
88
+ # end of the spec run, to help surface which specs are running
89
+ # particularly slow.
90
+ config.profile_examples = 10
91
+
92
+ # Run specs in random order to surface order dependencies. If you find an
93
+ # order dependency and want to debug it, you can fix the order by providing
94
+ # the seed, which is printed after each run.
95
+ # --seed 1234
96
+ config.order = :random
97
+
98
+ # Seed global randomization in this process using the `--seed` CLI option.
99
+ # Setting this allows you to use `--seed` to deterministically reproduce
100
+ # test failures related to randomization by passing the same `--seed` value
101
+ # as the one that triggered the failure.
102
+ Kernel.srand config.seed
103
+ =end
104
+ end
@@ -0,0 +1,51 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.rubygems_version = '1.3.5'
5
+
6
+ ## Leave these as is they will be modified for you by the rake gemspec task.
7
+ ## If your rubyforge_project name is different, then edit it and comment out
8
+ ## the sub! line in the Rakefile
9
+ s.name = 'rspec-sinatra'
10
+ s.version = '0.1.2'
11
+ s.date = '2014-10-13'
12
+ s.rubyforge_project = 'rspec-sinatra'
13
+
14
+ s.summary = "Initialize an rspec environment for sinatra"
15
+ s.description = "This little gem will help you to initialize an rspec environment for a sinatra application. It will generate the required files from templates."
16
+
17
+ s.authors = ["Sam Joseph"]
18
+ s.email = 'tansaku@gmail.com'
19
+ s.homepage = 'http://github.com/tansaku/rspec-sinatra'
20
+
21
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
22
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
23
+ s.require_paths = %w[lib]
24
+
25
+ s.executables = ["rspec-sinatra"]
26
+
27
+ s.rdoc_options = ["--charset=UTF-8"]
28
+ s.extra_rdoc_files = %w[README.md LICENSE]
29
+
30
+ s.add_dependency('templater', [">= 1.0.0"])
31
+
32
+ # = MANIFEST =
33
+ s.files = %w[
34
+ CHANGES.md
35
+ LICENSE
36
+ README.md
37
+ Rakefile
38
+ bin/rspec-sinatra
39
+ rspec-sinatra.gemspec
40
+ lib/rspec/sinatra.rb
41
+ lib/rspec/sinatra/generators.rb
42
+ lib/rspec/sinatra/templates/app.rbt
43
+ lib/rspec/sinatra/templates/config.ru
44
+ lib/rspec/sinatra/templates/spec/spec_helper.rbt
45
+ ]
46
+ # = MANIFEST =
47
+
48
+ ## Test files will be grabbed from the file list. Make sure the path glob
49
+ ## matches what you actually use.
50
+ #s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
51
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-sinatra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Sam Joseph
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: templater
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ description: This little gem will help you to initialize an rspec environment for
28
+ a sinatra application. It will generate the required files from templates.
29
+ email: tansaku@gmail.com
30
+ executables:
31
+ - rspec-sinatra
32
+ extensions: []
33
+ extra_rdoc_files:
34
+ - README.md
35
+ - LICENSE
36
+ files:
37
+ - CHANGES.md
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - bin/rspec-sinatra
42
+ - lib/rspec/sinatra.rb
43
+ - lib/rspec/sinatra/generators.rb
44
+ - lib/rspec/sinatra/templates/app.rbt
45
+ - lib/rspec/sinatra/templates/config.ru
46
+ - lib/rspec/sinatra/templates/spec/spec_helper.rbt
47
+ - rspec-sinatra.gemspec
48
+ homepage: http://github.com/tansaku/rspec-sinatra
49
+ licenses: []
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options:
53
+ - "--charset=UTF-8"
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project: rspec-sinatra
68
+ rubygems_version: 2.4.3
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: Initialize an rspec environment for sinatra
72
+ test_files: []