Skip to content

Instantly share code, notes, and snippets.

@shotty01
shotty01 / factories.rb
Last active Dec 15, 2015
view template rspec file - working. Switched to factory girl for data
View factories.rb
FactoryGirl.define do
factory :user do
login "login"
firstname Faker::Name.first_name
lastname Faker::Name.last_name
end
end
@shotty01
shotty01 / new.html.erb_spec.rb
Last active Dec 15, 2015
view spec for the create form of a user. it's passing. not using factory_girl and devise. Maybe that's wrong? previous version was webrat syntax. this version is capybara syntax. refactored a bit
View new.html.erb_spec.rb
require 'spec_helper'
require 'shared_examples_for_views'
describe "users/new" do
#generalized method to check a field
def check_field(form, id, options={})
field = form.find_field(id)
options.keys.each do |key|
field[key].should eq options[key].to_s
@shotty01
shotty01 / application_helper.rb
Last active Dec 15, 2015
my try for a working helper spec with devise and cancan. all tests pass but I'm still not happy about it. My worries are in the comments! --> changed from revision 3 to 7 to a shared_example and matcher usage. Revision 8 groups the shared examples together. Wording now better.
View application_helper.rb
module ApplicationHelper
def link_to_sprite(sprite_class, url_or_object, options={})
link_to url_or_object, options do
content_tag :i, :class => sprite_class do end
end
end
def render_button(obj, right, display, url_or_object, options={})
if can? right, obj