I hereby claim:
- I am cupakromer on github.
- I am cupakromer (https://keybase.io/cupakromer) on keybase.
- I have a public key ASDdHyS2jP9poEx6J_S1G7N5TLS52N-7YgxSMEbvRrOFdQo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
# No flash messages are set with this controller. | |
# | |
# This is a fairly basic / bare controller which does only the basic CRUD. | |
class BooksController < ApplicationController | |
respond_to :html, :xml, :json | |
before_action :set_book, only: [:show, :edit, :update, :destroy] | |
def index | |
respond_with @books = Book.all |
my_array = %w[test one two three] | |
# Inject takes the value of the block and passes it along | |
# This often causes un-intended errors | |
my_array.inject({}) do |transformed, word| | |
puts transformed | |
transformed[word] = word.capitalize | |
end | |
# Output: | |
# {} |
# spec/support/feature_sigin_helpers.rb | |
# Just some useful namespace | |
module KrackenFeatures | |
module SignInHelpers | |
def sign_in(person) | |
visit new_user_session_path | |
fill_in 'Email', with: person.email | |
fill_in 'Password', with: person.password |
class Calculator | |
def reduce(operator) | |
fail "You shouldn't be calling this directly!" | |
end | |
end | |
def uses_a_duck_type(calculation) | |
calculation.reduce(:+) | |
end |
class NotesController < ApplicationController | |
def index | |
notes = requested_notes | |
respond_to do |format| | |
format.html do | |
render :index, locals: { notes: notes } | |
end | |
format.json do | |
render :index, locals: { notes: notes } if stale? notes | |
end |
#!/usr/bin/env ruby | |
#encoding: UTF-8 | |
################################################################################ | |
################################################################################ | |
################################################################################ | |
# Overly simplistic implementation of how a RSpec test works # | |
################################################################################ |
describe MyClass do | |
context "with a barish foo" do | |
let(:foo) { :bar } | |
context "doing thing 1" do # #instance_method_1 | |
# ... | |
end | |
context "doing thing 2" do # #instance_method_2 |
def top_level_description(e) | |
top_level(e)[:description] | |
end | |
def top_level_object(e) | |
top_level(e)[:description_args].first | |
end | |
# Finds the top level example group. |
Normally when testing objects with RSpec, I prefer to setup the object state in top-level as context. Inside those contexts, the behavior (messages) are then each tested inside of that state. See ("TBD FILL IN HERE")[] for more details on this.
However, there are times you find yourself needing to pass in a lot of test cases for some behavior.