Search Results

Search found 260 results on 11 pages for 'rspec'.

Page 4/11 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11  | Next Page >

  • Testing a scoped find in a Rails controller with RSpec

    - by Joseph DelCioppio
    I've got a controller called SolutionsController whose index action is different depending on the value of params[:user_id]. If its nil, then it simply displays all of the solutions on my site, but if its not nil, then it displays all of the solutions for the given user id. Here it is: def index if(params[:user_id]) @solutions = @user.solutions.find(:all) else @solutions = Solution.find(:all) end end and @user is determined like this: private def load_user if(params[:user_id ]) @user = User.find(params[:user_id]) end end I've got an Rspec test to test the index action if the user is nil: describe "GET index" do context "when user_id is nil" do it "should find all of the solutions" do Solution.should_receive(:find).with(:all).and_return(@solutions) get :index end end end however, can someone tell me how I write a similar test for the other half of my controller, when the user id isn't nil? Something like: describe "GET index" do context "when user_id isn't nil" do before(:each) do @user = Factory.create(:user) @solutions = 7.times{Factory.build(:solution, :user => @user)} @user.stub!(:solutions).and_return(@solutions) end it "should find all of the solutions owned by a user" do @user.should_receive(:solutions).and_return(@solutions) get :index, :user_id => @user.id end end end But that doesn't work. Can someone help me out? Joe

    Read the article

  • Testing a scoped find in a Rails controller with RSpec

    - by Joseph DelCioppio
    I've got a controller called SolutionsController whose index action is different depending on the value of params[:user_id]. If its nil, then it simply displays all of the solutions on my site, but if its not nil, then it displays all of the solutions for the given user id. Here it is: def index if(params[:user_id]) @solutions = @user.solutions.find(:all) else @solutions = Solution.find(:all) end end and @user is determined like this: private def load_user if(params[:user_id ]) @user = User.find(params[:user_id]) end end I've got an Rspec test to test the index action if the user is nil: describe "GET index" do context "when user_id is nil" do it "should find all of the solutions" do Solution.should_receive(:find).with(:all).and_return(@solutions) get :index end end end however, can someone tell me how I write a similar test for the other half of my controller, when the user id isn't nil? Something like: describe "GET index" do context "when user_id isn't nil" do before(:each) do @user = Factory.create(:user) @solutions = 7.times{Factory.build(:solution, :user => @user)} @user.stub!(:solutions).and_return(@solutions) end it "should find all of the solutions owned by a user" do @user.should_receive(:solutions).and_return(@solutions) get :index, :user_id => @user.id end end end But that doesn't work. Can someone help me out? Joe

    Read the article

  • How to test views in ASP.NET MVC2 (ala RSpec)

    - by Dmitriy Nagirnyak
    Hi, I am really missing heavily the ability to test Views independently of controllers. The way RSpec allows to do it. What I want to do is to perform assertions on the rendered view (where no controller is involved!). In order to do so I should provide required Model, ViewData and maybe some details from HttpContextBase (when will we get rid of HttpContext!). So far I have not found anything that allows doing it. Also it might heavily depend on the ViewEngine being used. List of things that views might contain are: Partial views (may be nested deeply). Master pages (or similar in other view engines). Html helpers generating links and other elements. Generally almost anything in a range of common sense :) . Also please note that I am not talking about client-side testing and thus Selenium is just not related to it at all. It is just plain .NET testing. So are there any options to actually do the testing of views? Thanks, Dmitriy.

    Read the article

  • Test Views in ASP.NET MVC2 (ala RSpec)

    - by Dmitriy Nagirnyak
    Hi, I am really missing heavily the ability to test Views independently of controllers. The way RSpec does it. What I want to do is to perform assertions on the rendered view (where no controller is involved!). In order to do so I should provide required Model, ViewData and maybe some details from HttpContextBase (when will we get rid of HttpContext!). So far I have not found anything that allows doing it. Also it might heavily depend on the ViewEngine being used. List of things that views might contain are: Partial views (may be nested deeply). Master pages (or similar in other view engines). Html helpers generating links and other elements. Generally almost anything in a range of common sense :) . Also please note that I am not talking about client-side testing and thus Selenium is just not related to it at all. It is just plain .NET testing. So are there any options to actually do the testing of views? Thanks, Dmitriy.

    Read the article

  • Rails rspec expects Admin::PostsController, which is there.

    - by berkes
    I have a file app/controllers/admin/posts_controller.rb class Admin::PostsController < ApplicationController layout 'admin' # GET /admin/posts def index @pposts = Post.paginate :page => params[:page], :order => 'created_at DESC' end # ...Many more standard CRUD/REST methods... end And an rspec test spec/controllers/admin/posts_controller_spec.rb require 'spec_helper' describe Admin::PostsController do describe "GET 'index'" do it "should be successful" do get 'index' response.should be_success end end #...many more test for all CRUD/REST methods end However, running that spec throws an error. I have no idea what that error means, nor how to start solving it. /home/...../active_support/dependencies.rb:492:in `load_missing_constant': Expected /home/...../app/controllers/admin/posts_controller.rb to define Admin::PostsController (LoadError) I may have it all set up wrong, or may be doing something really silly, but all I want is my CRUD actions on /admin, with separate before filters and a separate layout. And to test these controllers. EDIT ZOMG, made a terrible copy-paste error into this SO posting. The controller was PostsController, not the PagesController that I pasted into there. Problem still stands, as my code is correct, just the SO post, here was wrong.

    Read the article

  • Integration test for H1 text failing when it should be passing (Rspec and Capybara)

    - by rebec
    Below you can see my test for what happens when a user tries to access the page to edit a profile photo that they don't own. I've used the same test on the NEW action, where it worked fine, but it surprised me by failing when I copied it down to the EDIT action tests. I've used save_and_open_page to test what Capybara's seeing (as you can see below); the resulting page definitely has an h1 with the specified text in it. No spelling errors, and case is all the same as in the test. I've tried using both have_css and have_selector. Both fail. I'm still learning Ruby, Rails, Rspec and especially Capybara (was using webrat previously and recently switched over), and wonder if I'm misconceiving of something that's making me expect this to pass when it doesn't. Any thoughts? Thanks! describe "EDIT" do let(:user) { FactoryGirl.create(:user) } let(:different_user) { FactoryGirl.create(:user) } let(:admin_user) { FactoryGirl.create(:user, role: "admin") } let(:profile_photo1) { FactoryGirl.create(:profile_photo, user: user) } subject { page } context "when signed in as any member" do before { login different_user visit edit_user_profile_photo_path(:id => profile_photo1, :user_id => profile_photo1.user_id) save_and_open_page } # It should deny access with an Unauthorised/Forbidden message. it { should have_css('h1', text: "Unauthorised/Forbidden.") } end

    Read the article

  • How to merge two test into one RSpec

    - by thefonso
    Both the last two test work individually...but when both are set to run (non pending) I get problems. question: can I create a test that merges the two into one? How would this look?(yes, I am new to rspec) require_relative '../spec_helper' # the universe is vast and infinite....and...it is empty describe "tic tac toe game" do context "the game class" do before (:each) do player_h = Player.new("X") player_c = Player.new("O") @game = Game.new(player_h, player_c) end it "method drawgrid must return a 3x3 game grid" do @game.drawgrid.should eq("\na #{$thegrid[:a1]}|#{$thegrid[:a2]}|#{$thegrid[:a3]} \n----------\nb #{$thegrid[:b1]}|#{$thegrid[:b2]}|#{$thegrid[:b3]} \n----------\nc #{$thegrid[:c1]}|#{$thegrid[:c2]}|#{$thegrid[:c3]} \n----------\n 1 2 3 \n") @game.drawgrid end #FIXME - last two test here - how to merge into one? it "play method must display 3x3 game grid" do STDOUT.should_receive(:puts).and_return("\na #{$thegrid[:a1]}|#{$thegrid[:a2]}|#{$thegrid[:a3]} \n----------\nb #{$thegrid[:b1]}|#{$thegrid[:b2]}|#{$thegrid[:b3]} \n----------\nc #{$thegrid[:c1]}|#{$thegrid[:c2]}|#{$thegrid[:c3]} \n----------\n 1 2 3 \n").with("computer move") @game.play end it "play method must display 3x3 game grid" do STDOUT.should_receive(:puts).with("computer move") @game.play end end end just for info here is the code containing the play method require_relative "player" # #Just a Tic Tac Toe game class class Game #create players def initialize(player_h, player_c) #bring into existence the board and the players @player_h = player_h @player_c = player_c #value hash for the grid lives here $thegrid = { :a1=>" ", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>" ", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" " } #make a global var for drawgrid which is used by external player class $gamegrid = drawgrid end #display grid on console def drawgrid board = "\n" board << "a #{$thegrid[:a1]}|#{$thegrid[:a2]}|#{$thegrid[:a3]} \n" board << "----------\n" board << "b #{$thegrid[:b1]}|#{$thegrid[:b2]}|#{$thegrid[:b3]} \n" board << "----------\n" board << "c #{$thegrid[:c1]}|#{$thegrid[:c2]}|#{$thegrid[:c3]} \n" board << "----------\n" board << " 1 2 3 \n" return board end #start the game def play #draw the board puts drawgrid #external call to player class @player = @player_c.move_computer("O") end end player_h = Player.new("X") player_c = Player.new("O") game = Game.new(player_h, player_c) game.play

    Read the article

  • RSpec test failing looking for a new set of eyes

    - by TheDelChop
    Guys, Here my issuse: I've got two models: class User < ActiveRecord::Base # Setup accessible (or protected) attributes for your model attr_accessible :email, :username has_many :tasks end class Task < ActiveRecord::Base belongs_to :user end with this simple routes.rb file TestProj::Application.routes.draw do |map| resources :users do resources :tasks end end this schema: ActiveRecord::Schema.define(:version => 20100525021007) do create_table "tasks", :force => true do |t| t.string "name" t.integer "estimated_time" t.datetime "created_at" t.datetime "updated_at" t.integer "user_id" end create_table "users", :force => true do |t| t.string "email" t.string "password" t.string "password_confirmation" t.datetime "created_at" t.datetime "updated_at" t.string "username" end add_index "users", ["email"], :name => "index_users_on_email", :unique => true add_index "users", ["username"], :name => "index_users_on_username", :unique => true end and this controller for my tasks: class TasksController < ApplicationController before_filter :load_user def new @task = @user.tasks.new end private def load_user @user = User.find(params[:user_id]) end end Finally here is my test: require 'spec_helper' describe TasksController do before(:each) do @user = Factory(:user) @task = Factory(:task) end #GET New describe "GET New" do before(:each) do User.stub!(:find).with(@user.id.to_s).and_return(@user) @user.stub_chain(:tasks, :new).and_return(@task) end it "should return a new Task" do @user.tasks.should_receive(:new).and_return(@task) get :new, :user_id => @user.id end end end This test fails with the following output: 1) TasksController GET New should return a new Task Failure/Error: get :new, :user_id => @user.id undefined method `abstract_class?' for Object:Class # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/base.rb:1234:in `class_of_active_record_descendant' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/base.rb:900:in `base_class' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/base.rb:655:in `reset_table_name' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/base.rb:647:in `table_name' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/base.rb:932:in `arel_table' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/base.rb:927:in `unscoped' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/named_scope.rb:30:in `scoped' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/base.rb:405:in `find' # ./app/controllers/tasks_controller.rb:15:in `load_user' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:431:in `_run__1954900289__process_action__943997142__callbacks' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:405:in `send' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:405:in `_run_process_action_callbacks' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:88:in `send' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:88:in `run_callbacks' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/callbacks.rb:17:in `process_action' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/rescue.rb:8:in `process_action' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/base.rb:113:in `process' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/rendering.rb:39:in `sass_old_process' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/gems/haml-3.0.0.beta.3/lib/sass/plugin/rails.rb:26:in `process' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/testing.rb:12:in `process_with_new_base_test' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/test_case.rb:390:in `process' # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/test_case.rb:328:in `get' # ./spec/controllers/tasks_controller_spec.rb:20 # /home/chopper/.rvm/gems/ruby-1.8.7-p249@rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:209:in `inject' Can anybody help me understand what's going on here? It seems to be an RSpec problem since the controller action actually works, but I could be wrong. Thanks, Joe

    Read the article

  • Spork servers super slow (>3m) to start for RSpec & Cucumber BDD

    - by Eric M.
    I recently installed a fresh development setup on my laptop and now notice that my instances of spork take several minutes to start up. This is also most likely of the RSpec and Cucumber tests start up times running super slow. I ran in diagnostic mode with the -d flag and received the output below. Anyone have a clue why this is suddenly happening? Spork Diagnosis - -- Summary -- config/boot.rb config/environment.rb config/initializers/backtrace_silencers.rb config/initializers/devise.rb config/initializers/hoptoad.rb config/initializers/inflections.rb config/initializers/mime_types.rb config/initializers/new_rails_defaults.rb config/initializers/session_store.rb spec/spec_helper.rb -- Detail -- --- config/boot.rb --- config/environment.rb:7 /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire' spec/spec_helper.rb:9 /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/bin/../lib/spork.rb:23:in `prefork' spec/spec_helper.rb:7 --- config/environment.rb --- spec/spec_helper.rb:9 /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/bin/../lib/spork.rb:23:in `prefork' spec/spec_helper.rb:7 --- config/initializers/backtrace_silencers.rb --- /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in load' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:622:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:in each' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:176:in process' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:insend' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:in run_without_spork' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/lib/spork/app_framework/rails.rb:18:inrun' config/environment.rb:9 /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire' spec/spec_helper.rb:9 /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/bin/../lib/spork.rb:23:in `prefork' spec/spec_helper.rb:7 --- config/initializers/devise.rb --- /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in load' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:622:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:in each' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:176:in process' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:insend' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:in run_without_spork' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/lib/spork/app_framework/rails.rb:18:inrun' config/environment.rb:9 /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire' spec/spec_helper.rb:9 /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/bin/../lib/spork.rb:23:in `prefork' spec/spec_helper.rb:7 --- config/initializers/hoptoad.rb --- /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in load' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:622:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:in each' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:176:in process' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:insend' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:in run_without_spork' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/lib/spork/app_framework/rails.rb:18:inrun' config/environment.rb:9 /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire' spec/spec_helper.rb:9 /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/bin/../lib/spork.rb:23:in `prefork' spec/spec_helper.rb:7 --- config/initializers/inflections.rb --- /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in load' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:622:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:in each' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:176:in process' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:insend' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:in run_without_spork' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/lib/spork/app_framework/rails.rb:18:inrun' config/environment.rb:9 /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire' spec/spec_helper.rb:9 /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/bin/../lib/spork.rb:23:in `prefork' spec/spec_helper.rb:7 --- config/initializers/mime_types.rb --- /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in load' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:622:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:in each' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:176:in process' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:insend' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:in run_without_spork' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/lib/spork/app_framework/rails.rb:18:inrun' config/environment.rb:9 /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire' spec/spec_helper.rb:9 /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/bin/../lib/spork.rb:23:in `prefork' spec/spec_helper.rb:7 --- config/initializers/new_rails_defaults.rb --- /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in load' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:622:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:in each' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:176:in process' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:insend' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:in run_without_spork' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/lib/spork/app_framework/rails.rb:18:inrun' config/environment.rb:9 /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire' spec/spec_helper.rb:9 /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/bin/../lib/spork.rb:23:in `prefork' spec/spec_helper.rb:7 --- config/initializers/session_store.rb --- /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in load' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:622:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:in each' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:621:inload_application_initializers' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:176:in process' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:insend' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/rails-2.3.5/lib/initializer.rb:113:in run_without_spork' /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/lib/spork/app_framework/rails.rb:18:inrun' config/environment.rb:9 /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' /Users/Eric/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire' spec/spec_helper.rb:9 /Users/Eric/.rvm/gems/ruby-1.8.7-p249@33n/gems/spork-0.8.2/bin/../lib/spork.rb:23:in `prefork' spec/spec_helper.rb:7 --- spec/spec_helper.rb ---

    Read the article

  • rspec testing a controller post changing my params from symbols to strings and breaking my tests

    - by ssmithstone
    In my controller spec I am doing this: it "should create new message" do Client.should_receive(:create).with({:title => 'Mr'}) post 'create' , :client => {:title => "Mr" } end ... and in my controller I am doing ... def create client = Client.create(params[:client]) end However this is failing with the following error message : expected: ({:title=>"Mr"}) got: ({"title"=>"Mr"}) I'm wondering why this is happening and how to get it to work

    Read the article

  • Test (with RSpec) a controller outside of a Rails environment

    - by ramon.tayag
    I'm creating a gem that will generate a controller for the Rails app that will use it. It's been a trial and error process for me when trying to test a controller. When testing models, it's been pretty easy, but when testing controllers, ActionController::TestUnit is not included (as described here). I've tried requiring it, and all similar sounding stuff in Rails but it hasn't worked. What would I need to require in the spec_helper to get the test to work? Thanks!

    Read the article

  • How rspec works with rails3 for integration-tests?

    - by makevoid
    What I'm trying to ahieve is to do integration tests with webrat in rails3 like Yehuda does with test-unit in http://pivotallabs.com/talks/76-extending-rails-3 minute 34. an example: describe SomeApp it "should show the index page" visit "/" body.should =~ /hello world/ end end Does someone knows a way to do it?

    Read the article

  • RSpec and stubbing parameters for a named scope

    - by Andy Waite
    I'm try to write a spec for a named scope which is date dependent. The spec: it "should return 6 months of documents" do Date.stub!(:today).and_return(Date.new(2005, 03, 03)) doc_1 = Factory.create(:document, :date => '2005-01-01') Document.past_six_months.should == [doc_1] end The named scope in the Document model: named_scope :past_six_months, :conditions => ['date > ? AND date < ?', Date.today - 6.months, Date.today] The spec fails with an empty array, and the query in test.log shows why: SELECT * FROM "documents" WHERE (date > '2009-11-11' AND date < '2010-05-11') i.e. it appears to be ignoring my stubbed Date method. However, if I use a class method instead of a named scope then it passes: def self.past_six_months find(:all, :conditions => ['date > ? AND date < ?', Date.today - 6.months, Date.today]) end I would rather use the named scope approach but I don't understand why it isn't working.

    Read the article

  • Drying repeated specs in RSpec

    - by snl
    In the test below, the Bar and Baz blocks contain identical specs. Leaving aside why such repetition was necessary in the first place, I'm wondering how one could dry this up. I tried turning the blocks into objects and calling them under Bar and Baz, but possibly because I did not get the scopes right, I have not been able to make it work. describe Foo do describe Bar do before(:each) do prepare end it "should do something" do true end it "should do something else" do true end end describe Baz do before(:each) do prepare_something_else end it "should do something" do true end it "should do something else" do true end end end

    Read the article

  • Trouble with RSpec's with method

    - by Thiago
    Hi there, I've coded the following spec: it "should call user.invite_friend" do user = mock_model(User, :id = 1) other_user = mock_model(User, :id = 2) User.stub!(:find).with(user.id).and_return(user) User.stub!(:find).with(other_user.id).and_return(other_user) user.should_receive(:invite_friend).with(other_user) post :invite, { :id = other_user.id }, {:user_id = user.id} end But I'm getting the following error when I run the specs NoMethodError in 'UsersController POST invite should call user.invite_friend' undefined method `find' for # Class:0x86d6918 app/controllers/users_controller.rb:144:in `invite' ./spec/controllers/users_controller_spec.rb:13: What's the mistake? Without .with it works just fine, but I want different return values for different arguments to the stub method. The following controller's actions might be relevant: def invite me.invite_friend(User.find params[:id]) respond_to do |format| format.html { redirect_to user_path(params[:id]) } end end def me User.find(session[:user_id]) end

    Read the article

  • How to remove duplication from RSpec

    - by Asa
    context "answer is correct" do before(:each) do @answer = stub_model(Answer, :correct => true).as_new_record assigns[:answer] = @answer render "answers/summarize" end it "should display flashcard context properly" do response.should contain("Quiz") end it "should summarize results" do response.should contain("is correct") end end context "answer is incorrect" do before(:each) do @answer = stub_model(Answer, :correct => false).as_new_record assigns[:answer] = @answer render "answers/summarize" end it "should display flashcard context properly" do response.should contain("Quiz") end it "should summarize results" do response.should contain("is incorrect") end end How do I avoid repeating the following block within both of the above contexts? it "should display flashcard context properly" do response.should contain("Quiz") end

    Read the article

  • Jruby rspec to be run parallely

    - by Priyank
    Hi. Is there something like Spork for Jruby too? We want to parallelize our specs to run faster and pre-load the classes while running the rake task; however we have not been able to do so. Since our project is considerable in size, specs take about 15 minutes to complete and this poses a serious challenge to quick turnaround. Any ideas are more than welcome. Cheers

    Read the article

  • should_receive in RSpec

    - by gmile
    As far as I know, should_receive is applied only to mock objects. What I want is to check, if a certain Class (not object) received a certain message, like: User.should_receive(:all).once How do I do that?

    Read the article

  • rspec and ruby 1.9.1: problem with dummy controller and routes

    - by giorgian
    I want to test a module that basically executes some verify statements, to ensure that actions are invoked with the correct method. # /lib/rest_verification.rb module RestVerification def self.included(base) # :nodoc: base.extend(ClassMethods) end module ClassMethods def verify_rest_actions verify :method => :post, :only => [:create], :redirect_to => { :action => :new } ... end end end I tried this: describe RestVerification do class FooController < ActionController::Base include RestVerification verify_rest_actions def new ; end def index ; end def create ; end def edit ; end def update ; end def destroy ; end end # controller_name 'foo' # this only works with ruby 1.8.7 : 1.9.1 says "uninitialized constant FooController" tests FooController # this works with both before(:each) do ActionController::Routing::Routes.draw do |map| map.resources :foo end end after(:each) do ActionController::Routing::Routes.reload! end it ':create should redirect to :new if invoked with wrong verb' do [:get, :put, :delete].each do |verb| send verb, :create response.should redirect_to(new_foo_url) end end ... end When testing: $ ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux] $ rake RestVerification :create should redirect to :new if invoked with wrong verb Finished in 0.175586 seconds $ rvm use 1.9.1 Using ruby 1.9.1 p378 $ rake RestVerification :create should redirect to :new if invoked with wrong verb (FAILED - 1) 1) 'RestVerification :create should redirect to :new if invoked with wrong verb' FAILED expected redirect to "http://test.host/foo/new", got redirect to "http://test.host/spec/rails/example/controller_example_group/subclass_1/foo/new" Is this a known issue? Is there a workaround?

    Read the article

  • Passing arguments to an Rspec SpecTask

    - by Bayard Randel
    Rake allows for the following syntax: task :my_task, :arg1, :arg2 do |t, args| puts "Args were: #{args}" end I'd like to be able to do the same, but with RSpecs SpecTask. The following unfortunately fails: desc "Run example with argument" SpecTask.new('my_task'), :datafile do |t, args| t.spec_files = FileList['cvd*_spec.rb -datafile=#{args}'] t.spec_opts = ["-c -f specdoc"] end Is it possible to achieve this with a SpecTask, or is there an alternative approach?

    Read the article

  • Writing a spec for helper with Ruby on Rails and RSpec

    - by TK
    I have been writing specs for controllers and models, but I have never written a helper spec. I have no idea where I start. I have the following snippet in application_helper.rb def title(page_title) content_for(:title) { page_title } end How should I write a helper spec on the code? Also if there's any open-source Rails app to show good helper testing/specing, do let me know.

    Read the article

  • Nested Resource testing RSpec

    - by Joseph DelCioppio
    I have two models: class Solution < ActiveRecord::Base belongs_to :owner, :class_name => "User", :foreign_key => :user_id end class User < ActiveRecord::Base has_many :solutions end with the following routing: map.resources :users, :has_many => :solutions and here is the SolutionsController: class SolutionsController < ApplicationController before_filter :load_user def index @solutions = @user.solutions end private def load_user @user = User.find(params[:user_id]) unless params[:user_id].nil? end end Can anybody help me with writing a test for the index action? So far I have tried the following but it doesn't work: describe SolutionsController do before(:each) do @user = Factory.create(:user) @solutions = 7.times{Factory.build(:solution, :owner => @user)} @user.stub!(:solutions).and_return(@solutions) end it "should find all of the solutions owned by a user" do @user.should_receive(:solutions) get :index, :user_id => @user.id end end And I get the following error: Spec::Mocks::MockExpectationError in 'SolutionsController GET index, when the user owns the software he is viewing should find all of the solutions owned by a user' #<User:0x000000041c53e0> expected :solutions with (any args) once, but received it 0 times Thanks in advance for all the help. Joe

    Read the article

  • Mocking view helpers with rspec-rails 2.0.0.beta.8

    - by snl
    I am trying to mock a view helper with rspec2. The old way of doing this throws an error, complaining the template object is not defined: template.should_receive(:current_user).and_return(mock("user")) Am I missing something here, or is this not implemented in rspec2 (yet)?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11  | Next Page >