Skip to content

Instantly share code, notes, and snippets.

@yosemsweet
yosemsweet / rspec_custom_matcher_capybara.rb
Created September 21, 2011 21:13
Capybara matchers in RSpec custom matcher
RSpec::Matchers.define :have_widget_elements_for do |widget|
match do |actual|
puts actual.to_yaml
@errors = {}
expected_elements = {
:widget => ".widget",
:content_type => ".#{widget.content_type}",
:body => ".body",
:title => ".title",
@yosemsweet
yosemsweet / authentication_tests.rb
Created September 19, 2011 20:47
Test authentication and authorization in controller specs
describe "POST create" do
it "should require authentication" do
should_require_authentication do
canvas = Factory.build(:canvas)
post :create,
:canvas => {
:name => canvas.name,
:mission => canvas.mission,
:image => canvas.image,
:open => canvas.open
@yosemsweet
yosemsweet / Updated code with cancan stubs
Created September 19, 2011 18:26
cancan ability caching issue
def should_require_authorization_of(*args, &action)
defaults = {:action => :manage, :object => nil, :not_authorized_status => 403}.merge(args.extract_options!)
options = defaults.merge(args.extract_options!)
user = Factory.build(:user)
user.stubs(:persisted?).returns(true)
controller.stubs(:current_user).returns(user)
authorize(options)
action.call
@yosemsweet
yosemsweet / initialization errors
Created March 24, 2011 14:53
Wherever the factories should be initialized it tries to initialize rss_feed.cfm instead
1:53:19 Information [jrpp-254] - [1 ms (1)] [/Users/yosem/workspace/suite101/custom_tags/ct_core/environment.cfc @ line: 5] - [environment] Setting environment
03/23 21:53:19 Information [jrpp-254] - [2 ms (1)] [/Users/yosem/workspace/suite101/custom_tags/ct_core/environment.cfc @ line: 11] - [environment] SUITE101_BETA_14104_21282626 - Setting server language details
03/23 21:53:19 Information [jrpp-254] - [3 ms (1)] [/Users/yosem/workspace/suite101/custom_tags/ct_core/environment.cfc @ line: 21] - [environment] SUITE101_BETA_14104_21282626 - Setting server strings
03/23 21:53:19 Information [jrpp-254] - [7 ms (4)] [/Users/yosem/workspace/suite101/custom_tags/ct_core/environment.cfc @ line: 168] - [environment] SUITE101_BETA_14104_21282626 - Setting local paths
03/23 21:53:19 Information [jrpp-254] - [9 ms (2)] [/Users/yosem/workspace/suite101/custom_tags/ct_core/environment.cfc @ line: 181] - [environment] SUITE101_BETA_14104_21282626 - Setting writer acquisition page urls
03/23 21:53:19 Information [j