swinger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in swinger.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ swinger (0.0.1)
5
+ capybara (~> 0.3.0)
6
+ rspec (>= 1.0.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ capybara (0.3.9)
12
+ culerity (>= 0.2.4)
13
+ mime-types (>= 1.16)
14
+ nokogiri (>= 1.3.3)
15
+ rack (>= 1.0.0)
16
+ rack-test (>= 0.5.4)
17
+ selenium-webdriver (>= 0.0.3)
18
+ childprocess (0.1.3)
19
+ ffi (~> 0.6.3)
20
+ culerity (0.2.12)
21
+ diff-lcs (1.1.2)
22
+ ffi (0.6.3)
23
+ rake (>= 0.8.7)
24
+ json_pure (1.4.6)
25
+ mime-types (1.16)
26
+ nokogiri (1.4.3.1)
27
+ rack (1.2.1)
28
+ rack-test (0.5.6)
29
+ rack (>= 1.0)
30
+ rake (0.8.7)
31
+ rspec (2.0.1)
32
+ rspec-core (~> 2.0.1)
33
+ rspec-expectations (~> 2.0.1)
34
+ rspec-mocks (~> 2.0.1)
35
+ rspec-core (2.0.1)
36
+ rspec-expectations (2.0.1)
37
+ diff-lcs (>= 1.1.2)
38
+ rspec-mocks (2.0.1)
39
+ rspec-core (~> 2.0.1)
40
+ rspec-expectations (~> 2.0.1)
41
+ rubyzip (0.9.4)
42
+ selenium-webdriver (0.0.29)
43
+ childprocess (>= 0.0.7)
44
+ ffi (~> 0.6.3)
45
+ json_pure
46
+ rubyzip
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ capybara (~> 0.3.0)
53
+ rspec (>= 1.0.0)
54
+ swinger!
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Copyright 2010 Jeff Kreeftmeijer.
2
+ You may use this work without restrictions, as long as this notice is included.
3
+ The work is provided "as is" without warranty of any kind, neither express nor implied.
data/README.textile ADDED
@@ -0,0 +1,45 @@
1
+ h1. Swinger
2
+
3
+ Swinger is a really simple "Capybara":http://github.com/jnicklas/capybara extension that aims to make driver switching in "RSpec":http://github.com/rspec/rspec a bit less horrible to look at. Using the new metadata feature in RSpec 2, you can simply set your @:driver@ per scenario or context:
4
+
5
+ <pre><code>
6
+ # `scenario` is an alias for `it` and `context` is an alias for `describe`, provided by Steak
7
+
8
+ scenario 'get a nice greeting', :driver => :selenium do
9
+ visit homepage
10
+ page.should have_content 'Welcome'
11
+ end
12
+
13
+ context 'when logged in', :driver => :rack_test do
14
+
15
+ scenario 'get a nice greeting' do
16
+ visit homepage
17
+ page.should have_content 'Welcome back'
18
+ end
19
+
20
+ scenario 'see the logout link' do
21
+ visit homepage
22
+ page.should have_content 'Logout'
23
+ end
24
+
25
+ end
26
+ </code></pre>
27
+
28
+ It also adds the @using_driver@ method to Capybara, allowing you to execute a block using a specific driver. This is especially useful when you're (still) not on RSpec 2 and can't use the new metadata feature:
29
+
30
+ <pre><code>
31
+ scenario 'get a nice greeting' do
32
+ Capybara.using_driver :selenium do
33
+ visit homepage
34
+ page.should have_content 'Welcome'
35
+ end
36
+ end
37
+ </code></pre>
38
+
39
+ h2. Installation
40
+
41
+ Installing Swinger is easy. Simply add it to your @Gemfile@ and require it in @spec_helper.rb@ (or @acceptance_helper.rb@ if you're using "Steak":http://github.com/cavalle/steak).
42
+
43
+ h2. Contributing
44
+
45
+ Found an issue? Have a great idea? Want to help? Great! Create an issue "issue":http://github.com/jeffkreeftmeijer/swinger/issues for it, "ask":http://github.com/inbox/new/jeffkreeftmeijer, or even better; fork the project and fix the problem yourself. Pull requests are always welcome. :)
data/lib/swinger.rb ADDED
@@ -0,0 +1,22 @@
1
+ if defined? RSpec::Core::Example
2
+ class RSpec::Core::Example
3
+
4
+ alias_method :__run_before_swinger, :run
5
+ private :__run_before_swinger
6
+
7
+ def run(*args)
8
+ Capybara.using_driver(metadata[:driver]) { __run_before_swinger(*args) }
9
+ end
10
+
11
+ end
12
+ end
13
+
14
+ module Capybara
15
+
16
+ def self.using_driver(driver)
17
+ Capybara.current_driver = driver
18
+ yield
19
+ Capybara.use_default_driver
20
+ end
21
+
22
+ end
@@ -0,0 +1,49 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'capybara/dsl'
4
+ require 'swinger'
5
+
6
+ # stolen from rspec-core's spec/spec_helper.rb
7
+
8
+ def sandboxed(&block)
9
+ begin
10
+ @orig_config = RSpec.configuration
11
+ @orig_world = RSpec.world
12
+ new_config = RSpec::Core::Configuration.new
13
+ new_config.include(RSpec::Matchers)
14
+ new_world = RSpec::Core::World.new(new_config)
15
+ RSpec.instance_variable_set(:@configuration, new_config)
16
+ RSpec.instance_variable_set(:@world, new_world)
17
+ object = Object.new
18
+ object.extend(RSpec::Core::ObjectExtensions)
19
+ object.extend(RSpec::Core::SharedExampleGroup)
20
+
21
+ (class << RSpec::Core::ExampleGroup; self; end).class_eval do
22
+ alias_method :orig_run, :run
23
+ def run(reporter=nil)
24
+ @orig_mock_space = RSpec::Mocks::space
25
+ RSpec::Mocks::space = RSpec::Mocks::Space.new
26
+ orig_run(reporter || NullObject.new)
27
+ ensure
28
+ RSpec::Mocks::space = @orig_mock_space
29
+ end
30
+ end
31
+
32
+ object.instance_eval(&block)
33
+ ensure
34
+ (class << RSpec::Core::ExampleGroup; self; end).class_eval do
35
+ remove_method :run
36
+ alias_method :run, :orig_run
37
+ remove_method :orig_run
38
+ end
39
+
40
+ RSpec.instance_variable_set(:@configuration, @orig_config)
41
+ RSpec.instance_variable_set(:@world, @orig_world)
42
+ end
43
+ end
44
+
45
+ RSpec.configure do |c|
46
+ c.around do |example|
47
+ sandboxed { example.run }
48
+ end
49
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Swinger' do
4
+
5
+ describe RSpec::Core::Example do
6
+
7
+ before do
8
+ @group = RSpec::Core::ExampleGroup.describe
9
+ end
10
+
11
+ it 'should call Capybara.using_driver' do
12
+ Capybara.should_receive(:using_driver).with(:selenium)
13
+ @group.example("does something", {:driver => :selenium}).run
14
+ end
15
+
16
+ it "does not show the original aliased method" do
17
+ methods = @group.example("without public aliased method").methods
18
+ methods.should_not include('__run_before_swinger')
19
+ end
20
+
21
+ end
22
+
23
+ describe Capybara do
24
+
25
+ it 'should set the driver using Capybara.current_driver=' do
26
+ Capybara.should_receive(:current_driver=).with(:selenium)
27
+ Capybara.using_driver(:selenium) {}
28
+ end
29
+
30
+ it 'should reset the driver using Capybara.use_default_driver' do
31
+ Capybara.should_receive(:use_default_driver)
32
+ Capybara.using_driver(:selenium) {}
33
+ end
34
+
35
+ it 'should yield the passed block' do
36
+ Capybara.should_receive(:yeah)
37
+ Capybara.using_driver(:selenium) { Capybara.yeah }
38
+ end
39
+
40
+ end
41
+
42
+ end
data/swinger.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "swinger"
5
+ s.version = '0.0.1'
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ['Jeff Kreeftmeijer']
8
+ s.email = ['jeff@kreeftmeijer.nl']
9
+ s.homepage = "http://rubygems.org/gems/swinger"
10
+ s.summary = %q{Capybara Driver swapping in RSpec}
11
+ s.description = %q{Swinger is a really simple Capybara extension that allows your Capybara to have multiple partners in one session.}
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
15
+ s.require_paths = ["lib"]
16
+
17
+ s.add_dependency('rspec', [">= 1.0.0"])
18
+ s.add_dependency('capybara', ["~> 0.3.0"])
19
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swinger
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jeff Kreeftmeijer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-01 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: capybara
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 0
48
+ - 3
49
+ - 0
50
+ version: 0.3.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Swinger is a really simple Capybara extension that allows your Capybara to have multiple partners in one session.
54
+ email:
55
+ - jeff@kreeftmeijer.nl
56
+ executables: []
57
+
58
+ extensions: []
59
+
60
+ extra_rdoc_files: []
61
+
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE
67
+ - README.textile
68
+ - lib/swinger.rb
69
+ - spec/spec_helper.rb
70
+ - spec/swinger_spec.rb
71
+ - swinger.gemspec
72
+ has_rdoc: true
73
+ homepage: http://rubygems.org/gems/swinger
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.7
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Capybara Driver swapping in RSpec
106
+ test_files: []
107
+