bbq 0.0.1 → 0.0.2.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +8 -0
  3. data/Gemfile +2 -1
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +152 -0
  6. data/Rakefile +29 -1
  7. data/bbq.gemspec +14 -4
  8. data/lib/bbq.rb +5 -1
  9. data/lib/bbq/devise.rb +53 -0
  10. data/lib/bbq/railtie.rb +7 -0
  11. data/lib/bbq/rspec.rb +86 -0
  12. data/lib/bbq/test.rb +36 -0
  13. data/lib/bbq/test_user.rb +61 -0
  14. data/lib/bbq/util.rb +19 -0
  15. data/lib/bbq/version.rb +1 -1
  16. data/lib/generators/bbq/install_generator.rb +5 -0
  17. data/lib/generators/bbq/test_generator.rb +5 -0
  18. data/lib/generators/rspec/bbq_install_generator.rb +18 -0
  19. data/lib/generators/rspec/bbq_test_generator.rb +9 -0
  20. data/lib/generators/rspec/templates/README +5 -0
  21. data/lib/generators/rspec/templates/bbq_spec.rb +7 -0
  22. data/lib/generators/rspec/templates/test_user.rb +5 -0
  23. data/lib/generators/test_unit/bbq_install_generator.rb +18 -0
  24. data/lib/generators/test_unit/bbq_test_generator.rb +9 -0
  25. data/lib/generators/test_unit/templates/README +5 -0
  26. data/lib/generators/test_unit/templates/bbq_test_case.rb +7 -0
  27. data/lib/generators/test_unit/templates/test_user.rb +5 -0
  28. data/lib/tasks/bbq.rake +15 -0
  29. data/test/dummy/Rakefile +7 -0
  30. data/test/dummy/app/controllers/application_controller.rb +3 -0
  31. data/test/dummy/app/controllers/home_controller.rb +11 -0
  32. data/test/dummy/app/helpers/application_helper.rb +2 -0
  33. data/test/dummy/app/models/user.rb +6 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/config.ru +4 -0
  36. data/test/dummy/config/application.rb +46 -0
  37. data/test/dummy/config/boot.rb +10 -0
  38. data/test/dummy/config/database.yml +3 -0
  39. data/test/dummy/config/environment.rb +5 -0
  40. data/test/dummy/config/environments/development.rb +26 -0
  41. data/test/dummy/config/environments/production.rb +49 -0
  42. data/test/dummy/config/environments/test.rb +35 -0
  43. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/test/dummy/config/initializers/devise.rb +194 -0
  45. data/test/dummy/config/initializers/inflections.rb +10 -0
  46. data/test/dummy/config/initializers/mime_types.rb +5 -0
  47. data/test/dummy/config/initializers/secret_token.rb +7 -0
  48. data/test/dummy/config/initializers/session_store.rb +8 -0
  49. data/test/dummy/config/locales/en.yml +5 -0
  50. data/test/dummy/config/routes.rb +6 -0
  51. data/test/dummy/db/schema.rb +19 -0
  52. data/test/dummy/public/404.html +26 -0
  53. data/test/dummy/public/422.html +26 -0
  54. data/test/dummy/public/500.html +26 -0
  55. data/test/dummy/public/favicon.ico +0 -0
  56. data/test/dummy/script/rails +6 -0
  57. data/test/dummy/spec/spec_helper.rb +10 -0
  58. data/test/dummy/test/test_helper.rb +2 -0
  59. data/test/support/helpers.rb +14 -0
  60. data/test/test_helper.rb +20 -0
  61. data/test/unit/bbq_devise_test.rb +39 -0
  62. data/test/unit/bbq_install_generator_test.rb +37 -0
  63. data/test/unit/bbq_rspec_test.rb +63 -0
  64. data/test/unit/bbq_test_generator_test.rb +23 -0
  65. data/test/unit/bbq_test_unit_test.rb +31 -0
  66. data/test/unit/bbq_test_user_test.rb +56 -0
  67. data/test/unit/bbq_two_simultaneous_users_test.rb +55 -0
  68. data/test/unit/bbq_util_test.rb +40 -0
  69. metadata +153 -11
data/.gitignore CHANGED
@@ -2,3 +2,11 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ bin/*
6
+ tmp/*
7
+ test/dummy/db/*.sqlite3
8
+ test/dummy/log/*.log
9
+ test/dummy/tmp/
10
+ test/dummy/test/acceptance/*
11
+ test/dummy/spec/acceptance/*
12
+ nbproject/
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ script: bundle exec rake test
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.8.7
5
+ - ree
6
+ - jruby
7
+ - rbx
8
+ - rbx-2.0
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in bbq.gemspec
4
3
  gemspec
4
+
5
+ gem "jruby-openssl", :platforms => :jruby
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 DRUG, Dolnośląska Grupa Użytkowników Ruby
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,152 @@
1
+ Warning & disclaimer
2
+ ====================
3
+
4
+ This gem is currently under development. We're targeting most popular use case - Rails. However the philosophy behind it is not limited to Rails nor web applications in general. There is even example usage with EventMachine. Feel free to modify it for your own needs.
5
+
6
+ [![Build Status](https://secure.travis-ci.org/drugpl/bbq.png)](http://travis-ci.org/drugpl/bbq)
7
+
8
+ BBQ
9
+ ===
10
+
11
+ Object oriented acceptance testing using personas.
12
+
13
+ * Ruby
14
+ * OOP
15
+ * DCI (Data Context Interaction) - for roles/personas
16
+ * Test framework independent, based on Capybara
17
+ * Opinionated
18
+
19
+ Difference from Cucumber
20
+ ========================
21
+
22
+ * No Gherkin
23
+ * Objects and methods instead of steps
24
+ * Easier code reuse
25
+ * No factories/fixtures
26
+
27
+ Example applications
28
+ ====================
29
+
30
+ * https://github.com/pawelpacana/roundtrip
31
+ * https://github.com/pawelpacana/eventmachine-bbq-example
32
+ * https://github.com/drugpl/drug-site
33
+
34
+ Installation
35
+ ============
36
+
37
+ First, add BBQ to your apps Gemfile:
38
+
39
+ ```ruby
40
+ # Gemfile
41
+ gem "bbq", :git => "git://github.com/drugpl/bbq.git"
42
+ ```
43
+
44
+ Run install generator:
45
+
46
+ ```
47
+ rails generate bbq:install
48
+ ```
49
+
50
+ Require BBQ in test/test_helper.rb:
51
+
52
+ ```ruby
53
+ require "bbq/test"
54
+ ```
55
+
56
+ Feature generator
57
+ =================
58
+
59
+ ```
60
+ rails g bbq:test MyFeatureName
61
+ ```
62
+
63
+ Examples
64
+ ========
65
+
66
+ ```ruby
67
+ test "admin can browse all user tickets" do
68
+ summaries = ["Forgot my password", "Page is not displayed correctly"]
69
+ descriptions = ["I lost my yellow note with password under the table!",
70
+ "My IE renders crap instead of crispy fonts!"]
71
+
72
+ alice = Roundtrip::TestUser.new
73
+ alice.extend(Roundtrip::TestUser::TicketReporter)
74
+ alice.register_and_login
75
+ alice.open_ticket(summaries.first, descriptions.first)
76
+
77
+ bob = Roundtrip::TestUser.new
78
+ bob.extend(Roundtrip::TestUser::TicketReporter)
79
+ bob.register_and_login
80
+ bob.open_ticket(summaries.second, descriptions.second)
81
+
82
+ bofh = Roundtrip::TestUser.new(:email => @admin.email)
83
+ bofh.extend(Roundtrip::TestUser::TicketManager)
84
+ bofh.login
85
+ bofh.visit "/support/admin/tickets"
86
+ assert bofh.see?(*summaries)
87
+ bofh.click_on(summaries.second)
88
+ assert bofh.see?(summaries.second, descriptions.second)
89
+ assert bofh.not_see?(summaries.first, descriptions.first)
90
+ end
91
+ ```
92
+
93
+ Deal with Devise
94
+ ================
95
+
96
+ ```ruby
97
+ require "bbq/test_user"
98
+ require "bbq/devise"
99
+
100
+ class TestUser < Bbq::TestUser
101
+ include Bbq::Devise
102
+ end
103
+ ```
104
+
105
+ After that TestUser have *login*, *logout*, *register*, *register_and_login* methods.
106
+
107
+ ```ruby
108
+ test "user register with devise" do
109
+ user = TestUser.new # or TestUser.new(:email => "email@example.com", :password => "secret")
110
+ user.register_and_login
111
+ user.see?("Stuff after auth")
112
+ end
113
+ ```
114
+
115
+ Development environment
116
+ =======================
117
+
118
+ ```
119
+ bundle install
120
+ bundle exec rake test
121
+ ```
122
+
123
+ Additional information
124
+ ======================
125
+
126
+ * 2 problems with Cucumber http://andrzejonsoftware.blogspot.com/2011/03/2-problems-with-cucumber.html
127
+ * Object oriented acceptance testing http://andrzejonsoftware.blogspot.com/2011/04/object-oriented-acceptance-testing.html
128
+ * Events in acceptance tests http://andrzejonsoftware.blogspot.com/2011/04/events-in-acceptance-tests.html
129
+
130
+ Maintainers
131
+ ===========
132
+
133
+ * Paweł Pacana (http://github.com/pawelpacana)
134
+ * Andrzej Krzywda (http://andrzejkrzywda.com)
135
+ * Michał Łomnicki (http://mlomnicki.com)
136
+ * Robert Pankowecki (http://robert.pankowecki.pl)
137
+ * Piotr Niełacny (http://ruby-blog.pl)
138
+
139
+ Contributors
140
+ ============
141
+
142
+ * Peter Suschlik (http://peter.suschlik.de)
143
+
144
+ Future plans
145
+ ============
146
+
147
+ * Events (http://andrzejonsoftware.blogspot.com/2011/04/events-in-acceptance-tests.html)
148
+
149
+ License
150
+ =======
151
+
152
+ MIT License
data/Rakefile CHANGED
@@ -1,2 +1,30 @@
1
- require 'bundler'
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
2
8
  Bundler::GemHelper.install_tasks
9
+ require 'rdoc/task'
10
+
11
+ RDoc::Task.new do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'Bbq'
14
+ rdoc.options << '--line-numbers' << '--inline-source'
15
+ rdoc.rdoc_files.include('README.rdoc')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
19
+
20
+ require 'rake/testtask'
21
+
22
+ Rake::TestTask.new(:test) do |t|
23
+ t.libs << 'lib'
24
+ t.libs << 'test'
25
+ t.pattern = 'test/**/*_test.rb'
26
+ t.verbose = false
27
+ end
28
+
29
+
30
+ task :default => :test
data/bbq.gemspec CHANGED
@@ -6,11 +6,11 @@ Gem::Specification.new do |s|
6
6
  s.name = "bbq"
7
7
  s.version = Bbq::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Paweł Pacana"]
10
- s.email = ["pawel.pacana@gmail.com"]
9
+ s.authors = ["DRUG - Dolnośląska Grupa Użytkowników Ruby"]
10
+ s.email = ["bbq@drug.org.pl"]
11
11
  s.homepage = ""
12
- s.summary = %q{Acceptance testing philosophy for grown-ups}
13
- s.description = %q{Objected oriented acceptance testing using personas and events.}
12
+ s.description = %q{Objected oriented acceptance testing for Rails, using personas.}
13
+ s.summary = %q{Objected oriented acceptance testing for Rails, using personas.}
14
14
 
15
15
  s.rubyforge_project = "bbq"
16
16
 
@@ -18,4 +18,14 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "capybara", "~> 1.0.0"
23
+ s.add_dependency "rails", ">= 3.0.0"
24
+
25
+ s.add_development_dependency "sqlite3", "~> 1.3.3"
26
+ s.add_development_dependency "rake", "~> 0.8.7"
27
+ s.add_development_dependency "rdoc", "~> 3.7"
28
+ s.add_development_dependency "devise", "~> 1.4.0"
29
+ s.add_development_dependency "rspec-rails", "~> 2.6.0"
30
+
21
31
  end
data/lib/bbq.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require 'bbq/railtie' if defined?(Rails)
2
+
1
3
  module Bbq
2
- # Your code goes here...
4
+ def self.root
5
+ @root ||= Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..')))
6
+ end
3
7
  end
data/lib/bbq/devise.rb ADDED
@@ -0,0 +1,53 @@
1
+ if defined?(Devise)
2
+
3
+ require 'bbq/test'
4
+
5
+ module Bbq
6
+ module Devise
7
+
8
+ attr_accessor :devise_authentication_key, :email, :password, :scope
9
+
10
+ def self.included(other)
11
+ other.add_callback(self)
12
+ end
13
+
14
+ def self.init(user)
15
+ user.devise_authentication_key = ::Devise.authentication_keys.first
16
+ user.email = user.options[user.devise_authentication_key.to_sym] || next_email
17
+ user.password = user.options[:password] || next_password
18
+ user.scope = ::Devise.mappings.first.second.singular.to_s
19
+ end
20
+
21
+ def register
22
+ visit send("new_#{self.scope}_registration_path")
23
+ fill_in "#{self.scope}_#{self.devise_authentication_key}", :with => @email
24
+ fill_in "#{self.scope}_password", :with => @password
25
+ fill_in "#{self.scope}_password_confirmation", :with => @password
26
+ find(:xpath, "//input[@name='commit']").click
27
+ end
28
+
29
+ def login
30
+ visit send("new_#{self.scope}_session_path")
31
+ fill_in "#{self.scope}_#{self.devise_authentication_key}", :with => @email
32
+ fill_in "#{self.scope}_password", :with => @password
33
+ find(:xpath, "//input[@name='commit']").click
34
+ end
35
+
36
+ def logout
37
+ visit send("destroy_#{self.scope}_session_path")
38
+ end
39
+
40
+ def register_and_login
41
+ register
42
+ end
43
+
44
+ def self.next_email
45
+ "#{ActiveSupport::SecureRandom.hex(3)}@example.com"
46
+ end
47
+
48
+ def self.next_password
49
+ ActiveSupport::SecureRandom.hex(8)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ module Bbq
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load Bbq.root.join("lib/tasks/bbq.rake")
5
+ end
6
+ end
7
+ end
data/lib/bbq/rspec.rb ADDED
@@ -0,0 +1,86 @@
1
+ require 'rspec/core'
2
+ require 'bbq/test_user'
3
+ require 'capybara/rspec/matchers'
4
+
5
+ module Bbq
6
+ module RSpecFeature
7
+ def self.included(base)
8
+ base.instance_eval do
9
+ alias :background :before
10
+ alias :scenario :it
11
+ end
12
+ end
13
+ end
14
+
15
+ class TestUser
16
+ def see!(*args)
17
+ args.each do |arg|
18
+ page.should have_content(arg)
19
+ end
20
+ end
21
+
22
+ def not_see!(*args)
23
+ args.each do |arg|
24
+ page.should have_no_content(arg)
25
+ end
26
+ end
27
+ end
28
+
29
+ module RSpecMatchers
30
+ class TestUserEyes
31
+ def initialize(negative, *args)
32
+ @args, @negative = args, negative
33
+ end
34
+
35
+ def matches?(actual)
36
+ @negative ? actual.not_see?(*@args) : actual.see?(*@args)
37
+ end
38
+
39
+ def failure_message_for_should
40
+ "expected to #{@negative ? negative_description : positive_description}"
41
+ end
42
+
43
+ def failure_message_for_should_not
44
+ "expected to #{@negative ? positive_description : negative_description}"
45
+ end
46
+
47
+ def description
48
+ @negative ? negative_description : positive_description
49
+ end
50
+
51
+ protected
52
+
53
+ def negative_description
54
+ "not see any of the following: #{@args.join(', ')}"
55
+ end
56
+
57
+ def positive_description
58
+ "see all of the following: #{@args.join(', ')}"
59
+ end
60
+ end
61
+
62
+ def see(*args)
63
+ TestUserEyes.new(false, *args)
64
+ end
65
+
66
+ def not_see(*args)
67
+ TestUserEyes.new(true, *args)
68
+ end
69
+ end
70
+ end
71
+
72
+ def self.feature(*args, &block)
73
+ options = if args.last.is_a?(Hash) then args.pop else {} end
74
+ options[:type] = :acceptance
75
+ options[:caller] ||= caller
76
+ args.push(options)
77
+
78
+ describe(*args, &block)
79
+ end
80
+
81
+ RSpec.configuration.include Bbq::RSpecFeature, :type => :acceptance
82
+
83
+ RSpec.configure do |config|
84
+ config.include Capybara::RSpecMatchers, :type => :acceptance
85
+ config.include Bbq::RSpecMatchers, :type => :acceptance
86
+ end
data/lib/bbq/test.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'active_support'
2
+ require 'test/unit'
3
+ require 'bbq/test_user'
4
+ require 'test/unit/assertions'
5
+
6
+ module Bbq
7
+
8
+ class TestCase < ActiveSupport::TestCase
9
+ class << self
10
+ alias :scenario :test
11
+ alias :background :setup
12
+ end
13
+
14
+ alias :background :setup
15
+ end
16
+
17
+ # test/unit specific methods for test_user
18
+ class TestUser
19
+
20
+ include Test::Unit::Assertions
21
+
22
+ def see!(*args)
23
+ args.each do |arg|
24
+ assert has_content?(arg), "Expecting to see \"#{arg}\", text not found."
25
+ end
26
+ end
27
+
28
+ def not_see!(*args)
29
+ args.each do |arg|
30
+ assert has_no_content?(arg), "Found \"#{arg}\", which was unexpected."
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end