bbq-rspec 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4e7617712f73b5b7b340497577d207d4580d0d4ef5055ab3ff7a33f1f1b1f1e7
4
+ data.tar.gz: a2098d9c920993d90bf8a87be822baceedcc2f783182b6419fc9e847e8d61280
5
+ SHA512:
6
+ metadata.gz: 1b6edb1a6122f0b154caa09ad0e0a7a5264f6b4853c65488e126c0490e605d84f55e9586d1c2715b63fcd58e5d1648f178145de2414437a4a80f10e54aeec75a
7
+ data.tar.gz: 27ebed9c4328a8c8b94ecce57e26ee56cffad37dea58728c7d7e7981971805212cbc76ab6b0586905a501a95de5bd8ef2fde00e198ddb1878dae1ea06858ac20
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
16
+ test/dummy/db/*.sqlite3
17
+ test/dummy/log/*.log
18
+ test/dummy/tmp/
19
+ Gemfile*.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.4
5
+ - rbx-19mode
6
+
7
+ gemfile:
8
+ - Gemfile.rspec2
9
+ - Gemfile.rspec3
data/Contributing.md ADDED
@@ -0,0 +1,9 @@
1
+ # Development setup
2
+
3
+ BUNDLE_GEMFILE=Gemfile.rspec2 bundle
4
+ BUNDLE_GEMFILE=Gemfile.rspec3 bundle
5
+
6
+ # Running specs
7
+
8
+ BUNDLE_GEMFILE=Gemfile.rspec2 bundle exec rake
9
+ BUNDLE_GEMFILE=Gemfile.rspec3 bundle exec rake
data/Gemfile.rspec2 ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'rspec', '~> 2.0'
5
+ gem 'bbq-core', github: 'drugpl/bbq-core'
data/Gemfile.rspec3 ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'rspec', '~> 3.0'
5
+ gem 'bbq-core', github: 'drugpl/bbq-core'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jakub Kosinski
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.
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,106 @@
1
+ # Bbq-rspec
2
+
3
+ [![Build Status](https://secure.travis-ci.org/drugpl/bbq-rspec.png)](http://travis-ci.org/drugpl/bbq-rspec) [![Dependency Status](https://gemnasium.com/drugpl/bbq-rspec.png)](https://gemnasium.com/drugpl/bbq-rspec) [![Code Climate](https://codeclimate.com/github/drugpl/bbq-rspec.png)](https://codeclimate.com/github/drugpl/bbq-rspec) [![Gem Version](https://badge.fury.io/rb/bbq-rspec.png)](http://badge.fury.io/rb/bbq-rspec)
4
+
5
+
6
+ RSpec integration for object oriented acceptance testing with [bbq](https://github.com/drugpl/bbq).
7
+
8
+ ## Setup
9
+
10
+ Add `bbq-rspec` to your `Gemfile`:
11
+
12
+ ```ruby
13
+ gem "bbq-rspec"
14
+ ```
15
+
16
+ Run install generator:
17
+
18
+ ```
19
+ bundle exec rails generate bbq:install
20
+ ```
21
+
22
+ Require BBQ in spec/spec_helper.rb:
23
+
24
+ ```ruby
25
+ require "bbq/rspec"
26
+ ```
27
+
28
+ ## Feature generator
29
+
30
+ ```
31
+ bundle exec rails g bbq:test MyFeatureName
32
+ ```
33
+
34
+ ## Running features
35
+
36
+ ```
37
+ bundle exec rake spec:acceptance
38
+ ```
39
+
40
+ ## Examples
41
+
42
+ ```ruby
43
+ class TestUser < Bbq::TestUser
44
+ def email
45
+ @options[:email] || "buyer@example.com"
46
+ end
47
+
48
+ module Buyer
49
+ def ask_question(question)
50
+ fill_in "question", :with => question
51
+ fill_in "email", :with => email
52
+ click_on("Ask")
53
+ end
54
+
55
+ def go_to_page_and_open_widget(page_url, &block)
56
+ go_to_page(page_url)
57
+ open_widget &block
58
+ end
59
+
60
+ def go_to_page(page_url)
61
+ visit page_url
62
+ wait_until { page.find("iframe") }
63
+ end
64
+
65
+ def open_widget
66
+ within_widget do
67
+ page.find("#widget h3").click
68
+ yield if block_given?
69
+ end
70
+ end
71
+
72
+ def within_widget(&block)
73
+ within_frame(widget_frame, &block)
74
+ end
75
+
76
+ def widget_frame
77
+ page.evaluate_script("document.getElementsByTagName('iframe')[0].id")
78
+ end
79
+ end
80
+ end
81
+ ```
82
+
83
+ ```ruby
84
+ feature "ask question widget" do
85
+ let(:user) {
86
+ user = TestUser.new(:driver => :webkit)
87
+ user.roles('buyer')
88
+ user
89
+ }
90
+
91
+ scenario "as a guest user, I should be able to ask a question" do
92
+ user.go_to_page_and_open_widget("/widget") do
93
+ user.ask_question "my question"
94
+ expect(user).to see("Thanks!")
95
+ end
96
+ end
97
+ end
98
+ ```
99
+
100
+ ## Contributing
101
+
102
+ 1. Fork it ( https://github.com/drugpl/bbq-rspec/fork )
103
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
105
+ 4. Push to the branch (`git push origin my-new-feature`)
106
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ end
8
+
9
+ task default: :spec
data/bbq-rspec.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bbq/rspec/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bbq-rspec"
8
+ spec.version = Bbq::RSpec::VERSION
9
+ spec.authors = ["DRUG - Dolnośląska Grupa Użytkowników Ruby"]
10
+ spec.email = ["bbq@drug.org.pl"]
11
+ spec.summary = %q{RSpec integration for bbq.}
12
+ spec.description = %q{RSpec integration for bbq.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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 "bbq-core", ">= 0.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", ">= 2.0"
26
+ end
data/lib/bbq/rspec.rb ADDED
@@ -0,0 +1,43 @@
1
+ require "bbq/core"
2
+ require "bbq/core/test_user"
3
+ require "bbq/rspec/version"
4
+ require "bbq/rspec/matchers"
5
+ require "rspec/core"
6
+ require "capybara/rspec/matchers"
7
+
8
+ module Bbq
9
+ module RSpec
10
+ module Feature
11
+ def self.included(base)
12
+ base.metadata[:type] = :acceptance
13
+ base.metadata[:caller] = caller
14
+
15
+ base.instance_eval do
16
+ alias :background :before
17
+ alias :scenario :it
18
+ alias :feature :describe
19
+ end
20
+ end
21
+ end
22
+
23
+ ::RSpec.configure do |config|
24
+ if Gem::Version.new(::RSpec::Core::Version::STRING) >= Gem::Version.new('2.99')
25
+ config.include Feature, :type => :acceptance, :file_path => %r{spec/acceptance}
26
+ else
27
+ config.include Feature, :type => :acceptance, :example_group => {:file_path => %r{spec/acceptance}}
28
+ end
29
+ config.include Matchers
30
+ config.after :each, :type => :acceptance do
31
+ ::Bbq::Core::Session.pool.release
32
+ end
33
+ end
34
+ end
35
+
36
+ module Core
37
+ class TestUser
38
+ include Capybara::RSpecMatchers
39
+ include ::Bbq::RSpec::Matchers
40
+ include ::RSpec::Matchers
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ require "bbq/rspec/matchers/see"
2
+
3
+ module Bbq
4
+ module RSpec
5
+ module Matchers
6
+ include See
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,71 @@
1
+ module Bbq
2
+ module RSpec
3
+ module Matchers
4
+ module See
5
+ class Matcher
6
+ attr_reader :text, :scope
7
+
8
+ def initialize(text)
9
+ @text = text
10
+ @scope = nil
11
+ end
12
+
13
+ def description
14
+ if scope
15
+ "see #{text} within #{scope}"
16
+ else
17
+ "see #{text}"
18
+ end
19
+ end
20
+
21
+ def matches?(actor)
22
+ @actual = page_fragment(actor)
23
+ @actual.has_text?(text)
24
+ end
25
+
26
+ def does_not_match?(actor)
27
+ @actual = page_fragment(actor)
28
+ @actual.has_no_text?(text)
29
+ end
30
+
31
+ def failure_message_for_should
32
+ "expected to see \"#{text}\" in #{format(@actual.text)}"
33
+ end
34
+ alias :failure_message :failure_message_for_should
35
+
36
+ def failure_message_for_should_not
37
+ "expected not to see \"#{text}\" in #{format(@actual.text)}"
38
+ end
39
+ alias :failure_message_when_negated :failure_message_for_should_not
40
+
41
+ def within(scope)
42
+ @scope = scope
43
+ self
44
+ end
45
+
46
+ private
47
+ def page_fragment(actor)
48
+ if scope
49
+ actor.page.first(*scope)
50
+ else
51
+ actor.page
52
+ end
53
+ end
54
+
55
+ def format(text)
56
+ case text
57
+ when Regexp
58
+ text.inspect
59
+ else
60
+ text.to_s.gsub(/[[:space:]]+/, ' ').strip.inspect
61
+ end
62
+ end
63
+ end
64
+
65
+ def see(text)
66
+ Matcher.new(text)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ module Bbq
2
+ module RSpec
3
+ VERSION = "0.3.0"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'attributes' do
4
+
5
+ specify 'acceptance type in spec/acceptance' do
6
+ expect(RSpec.current_example.metadata[:type]).to eq(:acceptance)
7
+ end
8
+
9
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'RSpec matchers' do
4
+
5
+ specify 'see given string' do
6
+ user = Bbq::Core::TestUser.new
7
+ user.visit('/test_page')
8
+
9
+ expect { expect(user).to see('Pink') }.to_not raise_error
10
+ end
11
+
12
+ specify 'unable to see given string' do
13
+ user = Bbq::Core::TestUser.new
14
+ user.visit('/test_page')
15
+
16
+ expect { expect(user).to see('nothing to see') }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
17
+ end
18
+
19
+ specify 'see given string within scope' do
20
+ user = Bbq::Core::TestUser.new
21
+ user.visit('/test_page')
22
+
23
+ expect { expect(user).to see('Pink').within('#unicorns') }.to_not raise_error
24
+ end
25
+
26
+ specify 'unable to see given string within scope' do
27
+ user = Bbq::Core::TestUser.new
28
+ user.visit('/test_page')
29
+
30
+ expect { expect(user).to see('Violet').within('#unicorns') }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
31
+ end
32
+
33
+ end
@@ -0,0 +1,25 @@
1
+ require 'bbq/rspec'
2
+ require 'rack/builder'
3
+
4
+ Bbq::Core.app = Rack::Builder.new do
5
+ map '/test_page' do
6
+ html_page = <<-EOP
7
+ <!DOCTYPE html>
8
+ <html>
9
+ <head>
10
+ <title>Ponycorns</title>
11
+ </head>
12
+ <body>
13
+ <ul id="unicorns">
14
+ <li>Pink</li>
15
+ </ul>
16
+ <ul id="ponies">
17
+ <li>Violet</li>
18
+ </ul>
19
+ </body>
20
+ </html>
21
+ EOP
22
+
23
+ run ->(env) { ['200', {'Content-Type' => 'text/html'}, [html_page]] }
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ class TestUserWithMatchers < Bbq::Core::TestUser
4
+ def ensure_no_red_ponycorns
5
+ expect(self).to have_no_content('Red')
6
+ end
7
+
8
+ def ensure_pink_ponycorns
9
+ expect(self).to see('Pink').within('#unicorns')
10
+ end
11
+ end
12
+
13
+ describe 'TestUser matchers' do
14
+
15
+ specify 'capybara matcher' do
16
+ user = TestUserWithMatchers.new
17
+ user.visit('/test_page')
18
+
19
+ expect { user.ensure_no_red_ponycorns }.not_to raise_error
20
+ end
21
+
22
+ specify 'bbq matcher' do
23
+ user = TestUserWithMatchers.new
24
+ user.visit('/test_page')
25
+
26
+ expect { user.ensure_pink_ponycorns }.not_to raise_error
27
+ end
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bbq-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - DRUG - Dolnośląska Grupa Użytkowników Ruby
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bbq-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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: '0.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ description: RSpec integration for bbq.
70
+ email:
71
+ - bbq@drug.org.pl
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Contributing.md
80
+ - Gemfile.rspec2
81
+ - Gemfile.rspec3
82
+ - LICENSE.txt
83
+ - MIT-LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - bbq-rspec.gemspec
87
+ - lib/bbq/rspec.rb
88
+ - lib/bbq/rspec/matchers.rb
89
+ - lib/bbq/rspec/matchers/see.rb
90
+ - lib/bbq/rspec/version.rb
91
+ - spec/acceptance/attributes_spec.rb
92
+ - spec/rspec_matchers_spec.rb
93
+ - spec/spec_helper.rb
94
+ - spec/test_user_matchers_spec.rb
95
+ homepage: ''
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: RSpec integration for bbq.
118
+ test_files:
119
+ - spec/acceptance/attributes_spec.rb
120
+ - spec/rspec_matchers_spec.rb
121
+ - spec/spec_helper.rb
122
+ - spec/test_user_matchers_spec.rb