Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
V. busy with Ably, building a great team 🚀

Matthew O'Riordan mattheworiordan

💭
V. busy with Ably, building a great team 🚀
View GitHub Profile
@mattheworiordan
mattheworiordan / example_integration_test.rb
Last active Aug 29, 2015
Proposed DLS and structure for our tests using Page objects
View example_integration_test.rb
require 'integration/spec_helper'
feature 'New user sign up', :js => true do
pages :home_page, :registration_page, :registration_complete_page
let(:user_email) { 'matt@econsultancy.com' }
scenario %{
User arrives on the home page, follows the sign up promotion,
fills in the form incorrectly, then corrects their mistakes,
@mattheworiordan
mattheworiordan / application.rb
Last active Oct 24, 2017
Cloudflare Middleware for Rails
View application.rb
# insert within your Application
config.middleware.insert_before(0, Rack::CloudFlareFixup)
@mattheworiordan
mattheworiordan / assign_locals_helper.rb
Last active Jun 30, 2017
Allow testing of locals when rendering Controllers
View assign_locals_helper.rb
def assigns_local(key)
controller.instance_variable_get('@patched_locals')[key]
end
def patch_controller_render_to_support_locals(controller)
def controller.render(options = nil, extra_options = {}, &block)
[options, extra_options].select { |o| o.kind_of?(Hash) }.each do |option_hash|
if option_hash.include?(:locals)
@patched_locals = option_hash[:locals]
end
@mattheworiordan
mattheworiordan / view_spec.rb
Created Jan 22, 2014
JSON view test example with shared _item.json partial
View view_spec.rb
describe 'JSON view test' do
let(:partial) { 'admin/case_studies/_item.json' }
let(:case_study) { build_stubbed(:case_study) }
it 'should render item partial' do
JSON.parse(render_item_partial).should == {
id: case_study.id,
title: case_study.title,
whatever: case_study.title
}
@mattheworiordan
mattheworiordan / gist:7374708
Created Nov 8, 2013
Econsultancy service objects following our discussion
View gist:7374708
AccountService.sign_up
AccountService.sign_up_for_existing_membership
AccountService.leave_membership
AccountService.move_to_new_membership
sign_up = AccountService.sign_up
if sign_up.success
...
else
errors = sign_up.errors
@mattheworiordan
mattheworiordan / rerun_rspec.rb
Created Sep 4, 2013
Rerun RSpec tests after parallel_tests failure
View rerun_rspec.rb
results = File.expand_path('../tmp/failing_specs.log', __FILE__)
if File.exists?(test_file)
tests = File.open(test_file).read.scan(/rspec .\/([^:]+:\d+)/)
if tests.present?
Dir.chdir(Rails.root) do
command = "bundle exec rspec #{tests.join(' ')}"
end
end
end
View fiddle.html
<div>Ably Quickstart example</div>
<ul id="output">
</ul>
Message: <input id="message" type="text" value="Hello"><br>
<input type="submit" id="publish" value="Publish the message">
</html>
View fiddle.css
body {
font-family: Helvetica, Verdana
}
p {
padding: 7px 10px;
}
#demo {
border: 1px solid #999;
}
View fiddle.html
<div>Ably Quickstart example</div>
<ul id="output">
</ul>
Message: <input id="message" type="text" value="Hello"><br>
<input type="submit" id="publish" value="Publish the message">
</html>