capybara_sfdc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara_sfdc.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Luminosity Group
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.
@@ -0,0 +1,51 @@
1
+ # Capybara SFDC
2
+
3
+ This is a gem that provides helpers for integration testing Visualforce apps
4
+ with Capybara. It makes use of the databasedotcom gem to allow you to use
5
+ fixtures that are automatically cleaned up between specs.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'capybara_sfdc'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install capybara_sfdc
20
+
21
+ ## Usage
22
+
23
+ Include the following in your `spec_helper.rb`:
24
+
25
+ ```ruby
26
+ require "bundler"
27
+ Bundler.require :default, :development
28
+ require "pp"
29
+ require "capybara"
30
+ require "capybara/dsl"
31
+ require "capybara/rspec"
32
+
33
+ Capybara.app_host = 'https://www.google.com'
34
+
35
+ CapybaraSfdc.configure do |config|
36
+ config.client_id = ENV['SFDC_CLIENT_ID']
37
+ config.client_secret = ENV['SFDC_CLIENT_SECRET']
38
+ config.username = ENV['SFDC_USERNAME']
39
+ config.password = ENV['SFDC_PASSWORD']
40
+ config.security_token = ENV['SFDC_SECURITY_TOKEN']
41
+ end
42
+ ```
43
+
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capybara_sfdc/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Eric J. Holmes"]
6
+ gem.email = ["eric@ejholmes.net"]
7
+ gem.description = %q{Gem to help with integration testing of visualforce apps with capybara}
8
+ gem.summary = %q{Gem to help with integration testing of visualforce apps with capybara}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "capybara_sfdc"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = CapybaraSfdc::VERSION
17
+
18
+ gem.add_dependency "capybara"
19
+ gem.add_dependency "databasedotcom"
20
+
21
+ gem.add_development_dependency "rspec"
22
+ end
@@ -0,0 +1,4 @@
1
+ require "capybara_sfdc/databasedotcom"
2
+ require "capybara_sfdc/rspec"
3
+ require "capybara_sfdc/version"
4
+ require "capybara_sfdc/config"
@@ -0,0 +1,52 @@
1
+ require 'capybara_sfdc/databasedotcom'
2
+ require 'capybara_sfdc/rspec'
3
+ require 'rspec'
4
+
5
+ module CapybaraSfdc
6
+ class << self
7
+ def configuration
8
+ @configuration ||= Configuration.new
9
+ end
10
+
11
+ # Retrieve the databasedotcom client
12
+ def client
13
+ @client
14
+ end
15
+
16
+ # Pass in a block to configure
17
+ def configure
18
+ yield configuration
19
+ client = Databasedotcom::Client.new :client_id => configuration.client_id, :client_secret => configuration.client_secret, :host => configuration.host
20
+ client.authenticate :username => configuration.username, :password => "#{CGI::escape(configuration.password)}#{configuration.security_token}"
21
+ ::RSpec.configure do |config|
22
+ config.before(:each) { client.cleanup }
23
+ config.after(:each) { client.cleanup }
24
+ config.include ::CapybaraSfdc::RSpec::Helpers
25
+ end if configuration.rspec
26
+ @client = client
27
+ end
28
+ end
29
+
30
+ class Configuration
31
+ # OAuth client id
32
+ attr_accessor :client_id
33
+ # OAuth client secret
34
+ attr_accessor :client_secret
35
+ # SFDC username
36
+ attr_accessor :username
37
+ # SFDC password
38
+ attr_accessor :password
39
+ # SFDC security token
40
+ attr_accessor :security_token
41
+ # Login host. Defaults to login.salesforce.com
42
+ attr_accessor :host
43
+
44
+ # Auto config rspec
45
+ attr_accessor :rspec
46
+
47
+ def initialize
48
+ @security_token = "login.salesforce.com"
49
+ @rspec = true
50
+ end
51
+ end
52
+ end
@@ -0,0 +1 @@
1
+ require 'capybara_sfdc/databasedotcom/client'
@@ -0,0 +1,38 @@
1
+ require 'databasedotcom'
2
+
3
+ module Databasedotcom
4
+ class Client
5
+
6
+ # Maybe there's a better way to do this but overriding the method should
7
+ # work
8
+ def create(class_or_classname, object_attrs)
9
+ class_or_classname = find_or_materialize(class_or_classname)
10
+ json_for_assignment = coerced_json(object_attrs, class_or_classname)
11
+ result = http_post("/services/data/v#{self.version}/sobjects/#{class_or_classname.sobject_name}", json_for_assignment)
12
+ new_object = class_or_classname.new
13
+ JSON.parse(json_for_assignment).each do |property, value|
14
+ set_value(new_object, property, value, class_or_classname.type_map[property][:type])
15
+ end
16
+ id = JSON.parse(result.body)["id"]
17
+ set_value(new_object, "Id", id, "id")
18
+ store(new_object)
19
+ new_object
20
+ end
21
+
22
+ def store(sobject)
23
+ created << sobject
24
+ end
25
+
26
+ def cleanup
27
+ created.each do |sobject|
28
+ sobject.delete
29
+ end
30
+ @created = []
31
+ end
32
+
33
+ def created
34
+ @created ||= []
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ require 'capybara_sfdc/rspec/config.rb'
2
+
3
+ module CapybaraSfdc
4
+ module RSpec
5
+ module Helpers
6
+
7
+ def db
8
+ ::CapybaraSfdc.client
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+ end
@@ -0,0 +1,3 @@
1
+ module CapybaraSfdc
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Databasedotcom do
4
+ let(:account) do
5
+ db.materialize('User')
6
+ db.materialize('Account')
7
+ Account.new(:Name => 'test', :OwnerId => User.first.Id).save
8
+ end
9
+
10
+ it "does something" do
11
+ puts account
12
+ end
13
+
14
+ it "does it again" do
15
+ puts account
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Google", :type => :request do
4
+ it "goes to google" do
5
+ visit '/'
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ require "bundler"
2
+ Bundler.require :default, :development
3
+ require "pp"
4
+ require "capybara"
5
+ require "capybara/dsl"
6
+ require "capybara/rspec"
7
+
8
+ Capybara.register_driver :firefox_no_ssl do |app|
9
+ require 'selenium/webdriver'
10
+ profile = Selenium::WebDriver::Firefox::Profile.new
11
+ profile.assume_untrusted_certificate_issuer = false
12
+
13
+ Capybara::Selenium::Driver.new(app, :profile => profile)
14
+ end
15
+
16
+ Capybara.default_driver = :firefox_no_ssl
17
+ Capybara.app_host = 'https://www.google.com'
18
+
19
+ CapybaraSfdc.configure do |config|
20
+ config.client_id = ENV['SFDC_CLIENT_ID']
21
+ config.client_secret = ENV['SFDC_CLIENT_SECRET']
22
+ config.username = ENV['SFDC_USERNAME']
23
+ config.password = ENV['SFDC_PASSWORD']
24
+ config.security_token = ENV['SFDC_SECURITY_TOKEN']
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara_sfdc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric J. Holmes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capybara
16
+ requirement: &2160746960 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2160746960
25
+ - !ruby/object:Gem::Dependency
26
+ name: databasedotcom
27
+ requirement: &2160769040 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2160769040
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &2160767620 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2160767620
47
+ description: Gem to help with integration testing of visualforce apps with capybara
48
+ email:
49
+ - eric@ejholmes.net
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - capybara_sfdc.gemspec
60
+ - lib/capybara_sfdc.rb
61
+ - lib/capybara_sfdc/config.rb
62
+ - lib/capybara_sfdc/databasedotcom.rb
63
+ - lib/capybara_sfdc/databasedotcom/client.rb
64
+ - lib/capybara_sfdc/rspec.rb
65
+ - lib/capybara_sfdc/rspec/config.rb
66
+ - lib/capybara_sfdc/version.rb
67
+ - spec/lib/databasedotcom/client_spec.rb
68
+ - spec/requests/google_spec.rb
69
+ - spec/spec_helper.rb
70
+ homepage: ''
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.15
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Gem to help with integration testing of visualforce apps with capybara
94
+ test_files:
95
+ - spec/lib/databasedotcom/client_spec.rb
96
+ - spec/requests/google_spec.rb
97
+ - spec/spec_helper.rb
98
+ has_rdoc: