steak 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ = Steak
2
+
3
+ Minimalist acceptance testing on top of RSpec
4
+
5
+ http://dl.dropbox.com/u/645329/steak_small.jpg
6
+
7
+ == What is Steak?
8
+
9
+ Steak is like Cucumber but in plain Ruby. This is how an acceptance spec looks like in Steak:
10
+
11
+ feature "Main page" do
12
+
13
+ background do
14
+ create_user :login => "jdoe"
15
+ login_as "jdoe"
16
+ end
17
+
18
+ scenario "should show existing quotes" do
19
+ create_quote :text => "The language of friendship is not words, but meanings",
20
+ :author => "Henry David Thoreau"
21
+
22
+ visit "/"
23
+
24
+ page.should have_css(".quote", :count => 1)
25
+ within(:css, ".quote") do
26
+ page.should have_css(".text", :text => "The language of friendship is not words, but meanings")
27
+ page.should have_css(".author", :text => "Henry David Thoreau")
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ No explicit givens, whens or thens. No steps, no english, just Ruby: RSpec, Steak and, in this example, some factories and Capybara. That's all.
34
+
35
+ If you are not in Rails but use RSpec, then Steak is just some aliases providing you with the language of acceptance testing (+feature+, +scenario+, +background+). If you are in Rails, you also have a couple of generators and full Rails integration testing (meaning Webrat support, for instance)
36
+
37
+ == Getting started
38
+
39
+ === Not in Rails
40
+
41
+ Just install and require the damned gem!
42
+
43
+ $ [sudo] gem install steak
44
+
45
+ Then in your spec or spec helper:
46
+
47
+ require 'rubygems'
48
+ require 'steak'
49
+
50
+ That's all. You don't really need to require RSpec.
51
+
52
+ === In Rails
53
+
54
+ Assuming you have already setup rspec-rails, add this to your project's <tt>config/environments/test.rb</tt>:
55
+
56
+ config.gem "steak"
57
+
58
+ Install the gem from the command line:
59
+
60
+ $ [sudo] RAILS_ENV=test rake gems:install
61
+
62
+ Run the generator:
63
+
64
+ $ script/generate steak
65
+
66
+ That will create some basic helper files and directory structure under the +spec+ directory, already configured for +Webrat+.
67
+
68
+ Now you may want to create your first acceptance spec:
69
+
70
+ $ script/generate acceptance_spec this_is_my_first_feature
71
+
72
+ You run your acceptance specs just like your regular specs. Individually...
73
+
74
+ $ spec spec/acceptance/this_is_my_first_feature_spec.rb
75
+
76
+ ...or all together:
77
+
78
+ $ spec spec/acceptance
79
+
80
+ == Credits
81
+
82
+ Steak is developed and maintained by Luismi Cavallé with the help and support of the rest of the BeBanjo team: Sergio Gil and Jorge Gómez Sancha.
83
+
84
+ Copyright (c) 2009 Luismi Cavallé, released under the MIT license
File without changes
@@ -0,0 +1,9 @@
1
+ class AcceptanceSpecGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.directory File.join('spec/acceptance', class_path)
5
+ file_name.gsub!(/_spec$/,"")
6
+ m.template 'acceptance_spec.rb', File.join('spec/acceptance', class_path, "#{file_name}_spec.rb")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/acceptance_helper'
2
+
3
+ feature "Feature name", %q{
4
+ In order to ...
5
+ As a ...
6
+ I want to ...
7
+ } do
8
+
9
+ scenario "Scenario name" do
10
+ true.should == true
11
+ end
12
+
13
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Sets up Steak in your Rails project. This will generate the spec/acceptance directory
3
+ and the necessary files.
4
+
5
+ If you haven't already, You should also run `./script/generate rspec` to complete the set up.
6
+
7
+ Examples:
8
+ `./script/generate steak`
@@ -0,0 +1,12 @@
1
+ class SteakGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.directory 'spec/acceptance/support'
5
+ m.directory 'lib/tasks'
6
+ m.file "acceptance_helper.rb", "spec/acceptance/acceptance_helper.rb"
7
+ m.file "helpers.rb", "spec/acceptance/support/helpers.rb"
8
+ m.file "paths.rb", "spec/acceptance/support/paths.rb"
9
+ m.file "steak.rake", "lib/tasks/steak.rake"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require "steak"
3
+ require "webrat"
4
+
5
+ Webrat.configure do |config|
6
+ config.mode = :rails
7
+ end
8
+
9
+ # Put your acceptance spec helpers inside /spec/acceptance/support
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -0,0 +1,4 @@
1
+ module HelperMethods
2
+ end
3
+
4
+ Spec::Runner.configuration.include(HelperMethods)
@@ -0,0 +1,7 @@
1
+ module NavigationHelpers
2
+ def homepage
3
+ "/"
4
+ end
5
+ end
6
+
7
+ Spec::Runner.configuration.include(NavigationHelpers)
@@ -0,0 +1,9 @@
1
+ load File.dirname(__FILE__) + '/rspec.rake'
2
+
3
+ namespace :spec do
4
+ desc "Run the code examples in spec/acceptance"
5
+ Spec::Rake::SpecTask.new(:acceptance => "db:test:prepare") do |t|
6
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
7
+ t.spec_files = FileList["spec/acceptance/**/*_spec.rb"]
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ module Spec::Example::ExampleGroupMethods
5
+ alias scenario example
6
+ alias background before
7
+ end
8
+
9
+ module Spec::DSL::Main
10
+ alias feature describe
11
+ end
12
+
13
+ if defined?(Spec::Rails)
14
+
15
+ module Spec::Rails::Example
16
+ class AcceptanceExampleGroup < IntegrationExampleGroup
17
+ include ActionController::RecordIdentifier
18
+ Spec::Example::ExampleGroupFactory.register(:acceptance, self)
19
+
20
+ def method_missing(sym, *args, &block)
21
+ return Spec::Matchers::Be.new(sym, *args) if sym.to_s =~ /^be_/
22
+ return Spec::Matchers::Has.new(sym, *args) if sym.to_s =~ /^have_/
23
+ super
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.dirname(__FILE__) + "/../../lib/steak"
4
+ require 'tempfile'
5
+
6
+ module Factories
7
+ def create_spec(options)
8
+ options = {:content => options} unless options.is_a?(Hash)
9
+ path = (options[:path] || Dir.tmpdir) + "/#{String.random}_spec.rb"
10
+ File.open(path, "w") do |file|
11
+ file.write options[:content]
12
+ end
13
+ path
14
+ end
15
+
16
+ def create_rails_app(options = {})
17
+ path = Dir.tmpdir + "rails_app_#{String.random}"
18
+ FileUtils.rm_rf path
19
+ `rails #{path}`
20
+ File.open(path + "/config/environments/test.rb", "a") do |file|
21
+ file.write "\nconfig.gem 'rspec-rails', :lib => false\n"
22
+ end
23
+ FileUtils.cp_r File.dirname(__FILE__) + "/../../", path + "/vendor/plugins/steak"
24
+
25
+ unless options[:setup_steak] == false
26
+ Dir.chdir path do
27
+ `script/generate rspec`
28
+ `script/generate steak`
29
+ end
30
+ end
31
+
32
+ path
33
+ end
34
+
35
+ end
36
+
37
+ module HelperMethods
38
+ def run_spec(file_path)
39
+ `spec #{file_path} 2>&1`
40
+ end
41
+ end
42
+
43
+ class String
44
+ CHARS = ('a'..'z').to_a + ('A'..'Z').to_a
45
+ def self.random(size = 8)
46
+ (0..size).map{ CHARS[rand(CHARS.length)] }.join
47
+ end
48
+ end
49
+
50
+ Spec::Runner.configuration.include(Factories)
51
+ Spec::Runner.configuration.include(HelperMethods)
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + "/acceptance_helper.rb"
2
+
3
+ feature "Acceptance spec generator for rails", %q{
4
+ In order to quickly add a new acceptance spec
5
+ As a developer
6
+ I want to run a generator that creates it for me
7
+ } do
8
+
9
+ background do
10
+ @rails_app = create_rails_app
11
+ end
12
+
13
+ scenario "Adding new acceptance spec" do
14
+ Dir.chdir @rails_app do
15
+ `script/generate acceptance_spec document_creation`
16
+ end
17
+
18
+ File.exist?(@rails_app + "/spec/acceptance/document_creation_spec.rb").should be_true
19
+ end
20
+
21
+ scenario "Adding new acceptance spec (plural name)" do
22
+ Dir.chdir @rails_app do
23
+ `script/generate acceptance_spec creating_documents`
24
+ end
25
+
26
+ File.exist?(@rails_app + "/spec/acceptance/creating_documents_spec.rb").should be_true
27
+ end
28
+
29
+ scenario "Adding new acceptance spec (pascalized name)" do
30
+ Dir.chdir @rails_app do
31
+ `script/generate acceptance_spec DocumentCreation`
32
+ end
33
+
34
+ File.exist?(@rails_app + "/spec/acceptance/document_creation_spec.rb").should be_true
35
+ end
36
+
37
+ scenario "Adding new acceptance spec (name ending with _spec)" do
38
+ Dir.chdir @rails_app do
39
+ `script/generate acceptance_spec document_creation_spec`
40
+ end
41
+
42
+ File.exist?(@rails_app + "/spec/acceptance/document_creation_spec.rb").should be_true
43
+ end
44
+
45
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + "/acceptance_helper.rb"
2
+
3
+ feature "Acceptance spec execution", %q{
4
+ In order to write better software
5
+ As a ruby developer
6
+ I want to execute acceptance specs
7
+ } do
8
+
9
+ scenario "Minimal acceptance spec" do
10
+ spec_file = create_spec <<-SPEC
11
+ require '#{File.dirname(__FILE__) + "/../../lib/steak"}'
12
+ feature "Minimal spec" do
13
+ scenario "First scenario" do
14
+ true.should be_true
15
+ end
16
+ end
17
+ SPEC
18
+ output = run_spec spec_file
19
+ output.should =~ /1 example, 0 failures/
20
+ end
21
+
22
+ scenario "Minimal acceptance spec that fails" do
23
+ spec_file = create_spec <<-SPEC
24
+ require '#{File.dirname(__FILE__) + "/../../lib/steak"}'
25
+ feature "Minimal spec" do
26
+ scenario "First scenario" do
27
+ true.should be_false
28
+ end
29
+ end
30
+ SPEC
31
+ output = run_spec spec_file
32
+ output.should =~ /1 example, 1 failure/
33
+ end
34
+
35
+ scenario "Acceptance spec with background" do
36
+ spec_file = create_spec <<-SPEC
37
+ require '#{File.dirname(__FILE__) + "/../../lib/steak"}'
38
+ feature "Minimal spec" do
39
+ background do
40
+ @value = 17
41
+ end
42
+ scenario "First scenario" do
43
+ @value.should == 17
44
+ end
45
+ end
46
+ SPEC
47
+ output = run_spec spec_file
48
+ output.should =~ /1 example, 0 failures/
49
+ end
50
+
51
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + "/acceptance_helper.rb"
2
+
3
+ feature "Acceptance spec execution", %q{
4
+ In order to write better web apps
5
+ As a rails developer
6
+ I want to execute acceptance specs
7
+ } do
8
+
9
+ scenario "Minimal acceptance spec" do
10
+ rails_app = create_rails_app
11
+ spec_file = create_spec :path => rails_app + "/spec/acceptance",
12
+ :content => <<-SPEC
13
+ require File.dirname(__FILE__) + "/acceptance_helper.rb"
14
+ feature "Minimal spec" do
15
+ scenario "First scenario" do
16
+ RAILS_ENV.should_not be_empty
17
+ RAILS_ENV.should == "test"
18
+ end
19
+ end
20
+ SPEC
21
+ output = run_spec spec_file
22
+ output.should =~ /1 example, 0 failures/
23
+ end
24
+
25
+ scenario "Integration stuff" do
26
+ rails_app = create_rails_app
27
+ spec_file = create_spec :path => rails_app + "/spec/acceptance",
28
+ :content => <<-SPEC
29
+ require File.dirname(__FILE__) + "/acceptance_helper.rb"
30
+ feature "Minimal spec" do
31
+ scenario "First scenario" do
32
+ get "/"
33
+ response.should have_text(/No route matches/)
34
+ end
35
+ end
36
+ SPEC
37
+ output = run_spec spec_file
38
+ output.should =~ /1 example, 0 failures/
39
+ end
40
+
41
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + "/acceptance_helper.rb"
2
+
3
+ feature "Steak generator for rails", %q{
4
+ In order to quickly start to hack my rails project with steak
5
+ As a developer
6
+ I want to run a generator that sets everything up for me
7
+ } do
8
+
9
+ scenario "Running generator in an empty project" do
10
+
11
+ rails_app = create_rails_app(:setup_steak => false)
12
+
13
+ Dir.chdir rails_app do
14
+ `script/generate steak`
15
+ end
16
+
17
+ File.exist?(rails_app + "/spec/acceptance/acceptance_helper.rb").should be_true
18
+ File.exist?(rails_app + "/spec/acceptance/support/helpers.rb").should be_true
19
+ File.exist?(rails_app + "/spec/acceptance/support/paths.rb").should be_true
20
+ File.exist?(rails_app + "/lib/tasks/steak.rake").should be_true
21
+
22
+ end
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steak
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - "Luismi Cavall\xC3\xA9"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-01 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Acceptance specs for Rails
17
+ email: luismi@lmcavalle.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - README.rdoc
26
+ - generators/acceptance_spec/USAGE
27
+ - generators/acceptance_spec/acceptance_spec_generator.rb
28
+ - generators/acceptance_spec/templates/acceptance_spec.rb
29
+ - generators/steak/USAGE
30
+ - generators/steak/steak_generator.rb
31
+ - generators/steak/templates/acceptance_helper.rb
32
+ - generators/steak/templates/helpers.rb
33
+ - generators/steak/templates/paths.rb
34
+ - generators/steak/templates/steak.rake
35
+ - lib/steak.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/cavalle/steak
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: A steak is a cucumber fermented in vinegar or brine
64
+ test_files:
65
+ - spec/acceptance/acceptance_helper.rb
66
+ - spec/acceptance/acceptance_spec_generator_spec.rb
67
+ - spec/acceptance/basic_spec.rb
68
+ - spec/acceptance/rails_spec.rb
69
+ - spec/acceptance/steak_generator_spec.rb