This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Animal | |
| def initialize(legs) | |
| @legs = legs | |
| end | |
| def legs_in_animal | |
| @legs | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def upcase(text): | |
| return text.upper() | |
| @upcase | |
| def words(text): | |
| return ' '.join(text) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resources :links do | |
| get :latest | |
| resources :comments | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe AController do | |
| describe 'GET index' do | |
| it 'returns the full list' do | |
| Model.should_receive(:find).with(:all) | |
| get :index | |
| response.code.should eq ("200") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [47, 46, 45, ...].each do |i| | |
| validates_numericality_of :"size_#{i}_quantity" | |
| define_method :"size_#{i}_quantity" do | |
| if self.variants.find_by_size(i) | |
| self.variants.count_on_hand | |
| else | |
| 0 | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe PostsController do | |
| describe "PUT #update" do | |
| let(:post) { Factory(:post) } | |
| before(:each) do | |
| sign_in user # user is defined as a memoized helper method using let { } below | |
| put :update, :id => post.id, :body => "new content" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe PostsController do | |
| describe "GET #index" do | |
| end | |
| describe "GET #show" do | |
| end | |
| describe "POST #create" do | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe PostsController do | |
| describe "PUT #update" do | |
| it "allows an author to edit a post" do | |
| post = Factory(:post) | |
| sign_in post.author | |
| put :update, :id => post.id, :body => "new content" | |
| response.should be_successful | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Run with: | |
| # rspec --color -d spec --format CustomFormatter --require ./spec/support/custom_formatter.rb | |
| require "rspec/core/formatters/documentation_formatter" | |
| class CustomFormatter < RSpec::Core::Formatters::DocumentationFormatter | |
| def example_group_started(example_group) | |
| output.puts example_group.file_path if @group_level == 0 | |
| super(example_group) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| post = BlogPost.find("4e13cda850b86112c9000001") | |
| # ... some operations that take some time ... | |
| post.save |