Skip to content

Instantly share code, notes, and snippets.

View nruth's full-sized avatar

Nicholas Rutherford nruth

View GitHub Profile
@nruth
nruth / selenium.rb
Last active March 22, 2023 13:10
translating old capybara selenium/chrome preferences and switches to new
# load into test setup after `require 'capybara/rails'`
# some sources for below flags and profile settings
# https://stackoverflow.com/questions/43143014/chrome-is-being-controlled-by-automated-test-software/43145088
# https://sqa.stackexchange.com/questions/26051/chrome-driver-2-28-chrome-is-being-controlled-by-automated-test-software-notif
# http://stackoverflow.com/questions/12211781/how-to-maximize-window-in-chrome-using-webdriver-python
# update sources for new Options object
# https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings
# https://github.com/teamcapybara/capybara/blob/master/lib/capybara/selenium/driver.rb
begin
@nruth
nruth / pay_stripe_helper.rb
Last active March 7, 2023 00:21
capybara selenium webdriver stripe.js checkout test helper
# -*- encoding : utf-8 -*-
module PayStripeHelpers
# must be used with driver: :selenium (or :sauce?)
def pay_stripe
sleep(0.7) # wait for the js to create the popup in response to pressing the button
within_frame 'stripe_checkout_app' do # must be selenium
# fill_in 'card_number', with: '4242424242424242' no longer works
4.times {page.driver.browser.find_element(:id, 'card_number').send_keys('4242')}
# fill_in 'cc-exp', with: '5/2018' no longer works
@nruth
nruth / clonetab.rb
Created July 18, 2010 20:25
OSX open new terminal tab @ current pwd
#!/usr/bin/env ruby
require 'fileutils'
extend FileUtils
cmd1 = "tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down"
cmd2 = "tell application \"Terminal\" to do script \"cd #{pwd}\" in the front window"
`osascript -e '#{cmd1}' -e '#{cmd2}'`
@nruth
nruth / gist:1264245
Last active August 23, 2021 01:57
Shared Capybara (or model setup) helpers for RSpec and Cucumber
# Let's assume you're driving Capybara in both RSpec request specs & Cucumber,
# for example you're using Cucumber as a design/documentation tool, and RSpec
# for the more boring integration tests.
# You don't want to duplicate your click-this-click-that helpers to e.g.
# log_in(username, password).
# You may also have model state setup code which can be shared/reused.
# Where can it go? How can it be loaded? I've been using the following approach:
#
@nruth
nruth / tests_spec.rb
Created July 30, 2010 20:48
how not to loop/nest rspec example groups (where you want to iterate diferent let/before variable values)
class Tests
SUBTESTS = %w(Abstract Decision Quantitative Verbal)
end
describe Tests do
describe "before assigning @ - " do
describe "this doesn't work because the loops are all at the same describe level (the befores override one another)" do
Tests::SUBTESTS.each do |test|
before(:each) do
@nruth
nruth / screenshots.rb
Last active November 12, 2020 19:27
show_me_the_pages: screenshot various screen resolutions with capybara to review responsive design
RSpec.configure do |config|
config.filter_run_excluding :show_me_the_pages unless ENV["SHOW_ME_THE_PAGES"]
end
class Screenshots
include Capybara::DSL
attr_accessor :resolutions
attr_accessor :output_path
@nruth
nruth / cookie_steps.rb
Created July 21, 2010 17:16
Testing login "remember me" feature with Capybara (rack::test or selenium) - deleting the session cookie (only)
@nruth
nruth / unpod.rb
Last active September 3, 2019 18:12
Ember Shucker - unpodding old projects (stupid simple grep/mv ruby fileutils script)
# pods aren't really a thing going forward, and come up as a problem during paid code reivews
# there is/was an alternative in the works to do with modules, but it's best to be on the old
# default ember-cli directory structure so that any new codemods can work
require 'fileutils'
app_pods = "app/pods"
puts "Shucking Routes"
routes = Dir.glob(File.join(app_pods, "**", "route.js"))
@nruth
nruth / migration-error.md
Created January 19, 2016 03:07
rails migration pg_dump: invalid option -- 'i'

If you start to see something like this, e.g. on Heroku since they installed the postgres 9.5 client libraries on their dynos

/usr/lib/postgresql/9.5/bin/pg_dump: invalid option -- 'i'
Try "pg_dump --help" for more information.
rake aborted!
Error dumping database
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/tasks/postgresql_database_tasks.rb:55:in `structure_dump'
@nruth
nruth / find_warn.rb
Last active July 17, 2019 09:39
Finding where deprecation warnings are coming from (Capybara, Rails, etc, anything that calls Kernel#warn)
TracePoint.trace(:c_call) do |tp|
# the various methods on tp tell you where warn is defined, but we want to know about the call stack,
# in particular the test code that the test library didn't like and decided to warn us about,
# so let's Array#grep the caller strings, filtering out the rspec library lines
if tp.method_id == :warn
app_lines = caller(0).grep(%r{enough-of-your-app-code-path-to-match/})
app_lines_without_reporter = app_lines.grep_v(/name-of-your-rspec-support-file-holding-this-code/)
p app_lines_without_reporter.join("\n")
p
end