This file contains 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 me with: | |
# | |
# $ watchr .watchr | |
# -------------------------------------------------- | |
# Convenience Methods | |
# -------------------------------------------------- | |
def growl(result) | |
result_lines = result.split("\n") |
This file contains 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
context "stores" do | |
it "should accept an array of Items and give back an array of Stores" do | |
i = Factory(:item) | |
i2 = Factory(:item) | |
i3 = Factory(:item, :auction => i2.store) | |
Item.stores([i,i2,i3]).should == [i.store, i2.store] | |
end | |
end |
This file contains 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
# Block helper | |
def block_to_partial(partial_name, options = {}, &block) | |
options.merge!(:body => capture(&block)) | |
concat(render(:partial => partial_name, :locals => options), block.binding) | |
end | |
def block(title, options = {}, &block) | |
block_to_partial('layouts/block', options.merge(:title => title), &block) | |
end |
This file contains 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 'POST create' do | |
context 'with valid params' do | |
before(:each) { User.any_instance.stub!(:valid?).and_return(true) } | |
it 'creates new user and redirects to the home page with a notice' do | |
post :create, :user => Factory.attributes_for(:user, :username => 'dude') | |
assigns[:user].should be_persisted | |
# assigns[:user].username.should eq('dude') # Unnecessary, model tests should cover this | |
flash[:notice].should_not be_blank # be_blank instead of be_nil | |
response.should redirect_to(root_path) # path here, not url | |
end |
This file contains 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 Item do | |
it {should belong_to(:store)} | |
[:stock_number, :manufacturer, :model].each do |attr| | |
it "must have a(n) #{attr}" do | |
i = Factory.build(:item, attr.to_s => nil) |
This file contains 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
rspec spec | |
....................../Library/Ruby/Gems/1.8/gems/rspec-rails-2.6.1/lib/rspec/rails/matchers/redirect_to.rb:5: warning: multiple values for a block parameter (2 for 1) | |
from /Library/Ruby/Gems/1.8/gems/rspec-expectations-2.6.0/lib/rspec/matchers/matcher.rb:23 | |
...../Library/Ruby/Gems/1.8/gems/rspec-rails-2.6.1/lib/rspec/rails/matchers/redirect_to.rb:5: warning: multiple values for a block parameter (2 for 1) | |
from /Library/Ruby/Gems/1.8/gems/rspec-expectations-2.6.0/lib/rspec/matchers/matcher.rb:23 | |
.........................../Library/Ruby/Gems/1.8/gems/rspec-rails-2.6.1/lib/rspec/rails/matchers/redirect_to.rb:5: warning: multiple values for a block parameter (2 for 1) | |
from /Library/Ruby/Gems/1.8/gems/rspec-expectations-2.6.0/lib/rspec/matchers/matcher.rb:23 | |
...../Library/Ruby/Gems/1.8/gems/rspec-rails-2.6.1/lib/rspec/rails/matchers/redirect_to.rb:5: warning: multiple values for a block parameter (2 for 1) | |
from /Library/Ruby/Gems/1.8/gems/rspec-expectations-2.6.0/lib/rspec/matchers/matcher.rb:23 | |
.. |
This file contains 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 update_store_cart | |
store = Store.find(params[:store_id]) | |
params[:item_ids] ||= [] | |
params[:item_ids].each do |i| | |
Cart.add(current_user.id, i) | |
end | |
current_user.items.each do |i| | |
Cart.drop(current_user.id, i.id) unless params[:item_ids].include?(i.id.to_s) || i.store != store |
This file contains 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
it "should accept nested attributes for Answer" do | |
question = Factory.attributes_for(:question) | |
question[:answers_attributes] = [Factory.attributes_for(:answer)] | |
survey = Factory.build(:survey) | |
survey.question_attributes = question | |
lambda { | |
survey.save | |
}.should change(Answer, :count).by(1) | |
end |
This file contains 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
Uncaught TypeError: Object http://localhost:3000/surveys/new# has no method 'prev' |
This file contains 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
User must have a(n) username | |
0.67032 seconds ./spec/models/user_spec.rb:12 | |
User should accept nested attributes for Department | |
0.59989 seconds ./spec/models/user_spec.rb:43 | |
User should accept nested attributes for Company | |
0.58664 seconds ./spec/models/user_spec.rb:19 | |
User should accept a Company object as company | |
0.5732 seconds ./spec/models/user_spec.rb:27 | |
User should not save a blank Company | |
0.56833 seconds ./spec/models/user_spec.rb:35 |