saki 0.0.2 → 0.0.3
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/README.markdown +33 -5
- data/VERSION +1 -1
- data/lib/generators/saki/install_generator.rb +39 -0
- data/lib/generators/saki/templates/acceptance_helper.rb +28 -0
- data/lib/generators/saki/templates/helpers.rb +6 -0
- data/lib/saki.rb +18 -2
- data/saki.gemspec +4 -1
- metadata +6 -3
data/README.markdown
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# Saki - For times when you can't swallow Cucumber
|
2
2
|
|
3
|
-
Saki lets you do acceptance testing on top of RSpec
|
3
|
+
Saki lets you do acceptance testing on top of RSpec. It is considerably more terse than cucumber, but does not sacrifice readability.
|
4
|
+
|
5
|
+
Are you tired of having DRY code, but tests that seem to babble on "for the length of a bible"? Me too. How about RSpec code that is hard to follow, when Ruby itself is as "human" as a programming language can get? I hate it too.
|
4
6
|
|
5
7
|
Enter Saki stage left.
|
6
8
|
|
7
9
|
## How terse is it?
|
8
10
|
|
9
|
-
Well, here's a sample that
|
11
|
+
Well, here's a sample that sets up contexts that create a user and then visit an edit path for that user.
|
10
12
|
|
11
13
|
with_existing :user do
|
12
14
|
on_visiting edit_path_for(:user) do
|
@@ -14,7 +16,7 @@ Well, here's a sample that assumes a user exists and visits an edit path for tha
|
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
This code basically injects some before blocks
|
19
|
+
This code basically injects some "before blocks", so it would look like this in vanilla RSpec:
|
18
20
|
|
19
21
|
context "when a user exists" do
|
20
22
|
before { @user = Factory :user }
|
@@ -24,11 +26,37 @@ This code basically injects some before blocks behind the scene, so it would loo
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
|
29
|
+
I feel Saki is much more expressive.
|
30
|
+
|
31
|
+
## What class-level methods does it use (for setting up contexts)?
|
32
|
+
|
33
|
+
`with_existing` takes a factory name as a symbol and assigns it to on instance variable with the same name.
|
34
|
+
|
35
|
+
`on_visiting` takes a path either as a string or as a lambda that executes within a before block to set up the path. This is useful when the code is dependent on an instance variable for path creation.
|
36
|
+
|
37
|
+
`on_visiting` has several helper functions for establishing a path: `create_path_for`, `index_path_for`, `edit_path_for`, `show_path_for` and `new_path_for`. These paths all take resource names for establishing a path. In cases where the resource is nested, it has a :parent => parent_resource option. This lets you set up blocks like:
|
38
|
+
|
39
|
+
on_visiting index_path_for(:auction)
|
40
|
+
|
41
|
+
`where` is a function taking as a parameter either a lambda to execute in the before block, or a symbol which is the name of a function to execute in the before block.
|
42
|
+
|
43
|
+
Finally, to simplify setting up integration tests, anything you wrap in an `integrate` block (like `describe`) sets the test type to acceptance.
|
44
|
+
|
45
|
+
## Installation
|
46
|
+
|
47
|
+
Saki installs with two steps. First, add to your Gemfile:
|
48
|
+
|
49
|
+
gem 'saki'
|
50
|
+
|
51
|
+
Then to fill out the directories run:
|
52
|
+
|
53
|
+
rails generate saki:install
|
28
54
|
|
55
|
+
Then, as long as your acceptance specs require the acceptance_helper file you should be good to go.
|
56
|
+
|
29
57
|
## What assumptions does it make?
|
30
58
|
|
31
|
-
It assumes that you are using factory_girl and capybara, though it probably would work fine with other test factories
|
59
|
+
It assumes that you are using factory_girl and capybara or webrat, though it probably would work fine with other test factories. If you need another factory in the mix, just redefine the `default_factory` method to behave how you want.
|
32
60
|
|
33
61
|
## Note on Patches/Pull Requests
|
34
62
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
AcceptanceDir = "acceptance"
|
3
|
+
|
4
|
+
module Saki
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
class_option :webrat, :desc => 'Use Webrat.', :type => :boolean
|
7
|
+
class_option :capybara, :desc => 'Use Capybara.', :type => :boolean
|
8
|
+
|
9
|
+
source_root File.join(File.dirname(__FILE__), 'templates')
|
10
|
+
|
11
|
+
desc <<-DESC
|
12
|
+
Description:
|
13
|
+
Sets up Saki in your Rails project. This will generate the
|
14
|
+
spec/acceptance directory and the necessary files.
|
15
|
+
|
16
|
+
If you haven't already, You should also run
|
17
|
+
`rails generate rspec:install` to complete the set up.
|
18
|
+
|
19
|
+
Examples:
|
20
|
+
`rails generate saki:install`
|
21
|
+
DESC
|
22
|
+
|
23
|
+
def initialize(args=[], options={}, config={})
|
24
|
+
puts "Defaulting to Capybara..." if options.empty?
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def manifest
|
29
|
+
empty_directory "spec/#{AcceptanceDir}/support"
|
30
|
+
template "acceptance_helper.rb", "spec/#{AcceptanceDir}/acceptance_helper.rb"
|
31
|
+
copy_file "helpers.rb", "spec/#{AcceptanceDir}/support/helpers.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
def driver
|
35
|
+
@driver = options.webrat? ? 'webrat' : 'capybara'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
<%- if driver == 'webrat' %>
|
4
|
+
require "webrat"
|
5
|
+
|
6
|
+
Webrat.configure do |config|
|
7
|
+
config.mode = :rack
|
8
|
+
end
|
9
|
+
|
10
|
+
module Saki::Webrat
|
11
|
+
include Rack::Test::Methods
|
12
|
+
include Webrat::Methods
|
13
|
+
include Webrat::Matchers
|
14
|
+
def app
|
15
|
+
Rails.application
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configuration.include Saki::Webrat, :type => :acceptance
|
20
|
+
|
21
|
+
<%- else -%>
|
22
|
+
require 'capybara/rails'
|
23
|
+
|
24
|
+
RSpec.configuration.include Capybara, :type => :acceptance
|
25
|
+
<%- end -%>
|
26
|
+
|
27
|
+
# Put your acceptance spec helpers inside /spec/acceptance/support
|
28
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
data/lib/saki.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
|
1
3
|
module Saki
|
2
4
|
module AcceptanceHelpers
|
3
5
|
extend ActiveSupport::Concern
|
@@ -123,9 +125,13 @@ module Saki
|
|
123
125
|
end
|
124
126
|
end
|
125
127
|
|
126
|
-
def where(
|
128
|
+
def where(executable, &block)
|
127
129
|
context "anonymous closure" do
|
128
|
-
|
130
|
+
if executable.is_a? Symbol
|
131
|
+
before { send executable }
|
132
|
+
else
|
133
|
+
before { instance_eval &executable }
|
134
|
+
end
|
129
135
|
module_eval &block
|
130
136
|
end
|
131
137
|
end
|
@@ -133,4 +139,14 @@ module Saki
|
|
133
139
|
end
|
134
140
|
end
|
135
141
|
|
142
|
+
module RSpec::Core::ObjectExtensions
|
143
|
+
def integrate(*args, &block)
|
144
|
+
args << {} unless args.last.is_a?(Hash)
|
145
|
+
args.last.update :type => :acceptance
|
146
|
+
describe(*args, &block)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
|
136
152
|
RSpec.configuration.include Saki::AcceptanceHelpers, :type => :acceptance
|
data/saki.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{saki}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nate Kidwell"]
|
@@ -23,6 +23,9 @@ Gem::Specification.new do |s|
|
|
23
23
|
"README.markdown",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
|
+
"lib/generators/saki/install_generator.rb",
|
27
|
+
"lib/generators/saki/templates/acceptance_helper.rb",
|
28
|
+
"lib/generators/saki/templates/helpers.rb",
|
26
29
|
"lib/saki.rb",
|
27
30
|
"saki.gemspec",
|
28
31
|
"test/helper.rb",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nate Kidwell
|
@@ -48,6 +48,9 @@ files:
|
|
48
48
|
- README.markdown
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
|
+
- lib/generators/saki/install_generator.rb
|
52
|
+
- lib/generators/saki/templates/acceptance_helper.rb
|
53
|
+
- lib/generators/saki/templates/helpers.rb
|
51
54
|
- lib/saki.rb
|
52
55
|
- saki.gemspec
|
53
56
|
- test/helper.rb
|