Skip to content

Instantly share code, notes, and snippets.

View arwagner's full-sized avatar

Andrew Wagner arwagner

  • Northern Virginia
View GitHub Profile
@arwagner
arwagner / gist:703446
Created November 17, 2010 14:38
MarbleMachine spec
shared_examples_for "blue green yellow" do
let(:current_context) { [:blue, :green, :yellow].each {|color| machine.insert color }; machine }
end
shared_examples_for "small medium large" do
let(:current_context) { [:small, :medium, :large].each {|size| machine.press size }; machine }
end
describe MarbleMachine do
let(:machine) { MarbleMachine.new }
@arwagner
arwagner / gist:1083428
Created July 14, 2011 20:58
Shadowing in ruby
class User
def self.ceo
new("Fred")
end
def self.all_managers
[User.new("Wilma")]
end
def initialize name
@arwagner
arwagner / gist:1129858
Created August 6, 2011 23:00
bundler error
awagner:/c/projects/ruby/crafting/templater $ bundle exec rails --version
openpath: pathname too long (ignored)
Directory "c:/users/awagner"
File "rails"
bundler: command not found: rails
Install missing gem binaries with `bundle install`
Before the rebase:
* 66ad91d (origin/master, origin/HEAD, master) don't build the
| * 097f260 (HEAD, origin/travis-ci, travis-ci) specify ruby ve
| * 7f15aa9 Settup up bundler and the rake tests for travis-ci.
|/
* eea1cb5 (origin/fixing_tests, fixing_tests) Getting all rspec
* 251ea7d Removed superfluous methods from MethodParameters
After:
class DepositController < ApplicationController
def index
@deposit = Deposit.search(search_param)
@deposit_presenter = DepositPresenter.new(deposit)
end
end
# this should either be in lib, or in app/presenters or something
class DepositPresenter
def initialize(search)
@arwagner
arwagner / gist:1260244
Created October 3, 2011 21:02
fun times
code_str = <<RUBY
class Foo
attr_reader :bar1
attr_reader :bar2
end
RUBY
smelly_classes = Reek2.parse(code_str) do
classes.where do |klass|
calls = klass.calls_to(:attr_reader)
calls.count > 1
@arwagner
arwagner / gist:1262573
Created October 4, 2011 19:39
more fun
require 'reek2'
describe "smell detection" do
context "attribute" do
it "detects when there are 2 attr_readers in one class" do
pending
code_str = <<RUBY
class Foo
attr_reader :bar1
attr_reader :bar2
# YAML report
smell_results = {}
smells.each do |smell|
smell_results[smell.name] = smell.results
end
puts y smell_results
# reek does this at the top level somewhere
# (which means you could define your own smell at the top level somewhere too)
smell :duplication do |code|
code.methods.where do |method|
method.method_calls.where do |call|
method.method_calls.where do |call2|
call2 == call
end.count > 1
end.count > 1
end
/Users/andrewwagner/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find bundler (>= 0) amongst [minitest-1.6.0, rake-0.8.7, rdoc-2.5.8] (Gem::LoadError)
from /Users/andrewwagner/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /Users/andrewwagner/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems.rb:1195:in `gem'
from /Users/andrewwagner/.rvm/gems/ruby-1.9.2-p290/bin/bundle:18:in `<main>'
new-host-3%