rspec-rails

RSpec 1.3.3 Rails 2.3.9 Webrat 0.7.3 “undefined method `assign`”

假如想象 提交于 2019-12-10 15:43:48
问题 My spec require 'spec_helper' describe 'user_sessions/new.html.erb' do let (:user_session) { mock_model(UserSession).as_null_object } before do assign(:user_session, user_session) end it 'should have the sign in header' do render rendered.should contain('Sign in') end end Throws 1) NoMethodError in 'user_sessions/new.html.erb should have the sign in header' undefined method `assign' for #<Spec::Rails::Example::ViewExampleGroup::Subclass_1:0x1036835e0> Gems: group :test, :cucumber do gem

Rails / Rspec - writing spec for class name of belongs_to association

笑着哭i 提交于 2019-12-10 15:04:27
问题 Given the code below: (1) How would you write a spec to test that the class name of home_team and away_team should be a Team class? (2) Should you even bother to write such a spec? I'm not sure I see the value in doing so, but wanted to get your thoughts. class Event < ActiveRecord::Base belongs_to :home_team, :class_name => 'Team', :foreign_key => :home_team_id belongs_to :away_team, :class_name => 'Team', :foreign_key => :away_team_id end describe Event do it { should belong_to(:home_team)

RSpec Error Regarding Selenium-Webdriver

两盒软妹~` 提交于 2019-12-10 14:56:28
问题 Trying to get through Michael Hartl's tutorial; encountering issues here. I've just created the application. Here is what I am presented with when I run 'bundle exec rspec spec/requests/static_pages_spec.rb' Corey-M-Kimball:sample_app coreymkimball$ bundle exec rspec spec/requests/static_pages_spec.rb /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common/zipper.rb:1:in `require': cannot load such file -- zip/zip

Capybara choose(“radio button”) not working

拈花ヽ惹草 提交于 2019-12-10 06:06:29
问题 A snapshot of my view: <%= form_for @request do |f| %> <div class="form-group"> <%= f.radio_button(:item, "Snow/waterproof shell (upper)") %> <%= f.label(:item, "Snow/waterproof shell (upper)") %> </br> <%= f.radio_button(:item, "Headlamp") %> <%= f.label(:item, "Headlamp") %> </div> Yet on my Rspec integration test file (spec/requests/requests_spec.rb), when I write (note the choose radio button is a part of the form where the user requests an item from a list, and the test is for the

method stubbing on before(:all)

亡梦爱人 提交于 2019-12-10 01:44:25
问题 require './spec/spec_helper' require './bank' describe Bank do context "#transfer" do before(:all) do @customer1 = Customer.new(500) customer2 = Customer.new(0) @customer1.stub(:my_money).and_return(1000) customer2.stub(:my_money).and_return(0) @transfer_message = Bank.new.transfer(@customer1, customer2, 2000) end it "should return insufficient balance if transferred amount is greater than balance" do expect(@transfer_message).to eq("Insufficient funds") end it "calls my_money" do expect(

Why is the rack env hash empty in Rails test environment?

…衆ロ難τιáo~ 提交于 2019-12-09 16:43:12
问题 In my Rails app, I'm accessing the env hash in one of my controller actions. Something along the lines of: def my_before_filter env['some.key'] = "Something or other" end This works great for my requirements. If I start my Rails app in test environment, and visit an action like: # /users in UsersController#index def index puts env.inspect end Then the content of the env hash is output to the console as expected. When I get this action from within an RSPec example, the output is an empty hash?

`require': cannot load such file — spec_helper (LoadError)

孤街醉人 提交于 2019-12-09 16:22:15
问题 I am creating bundler gem --test=rspec MyGem. in which I'm getting the repository structure. When I try to run the rspec code I get the following error: `require': cannot load such file -- spec_helper (LoadError) I then try to apply require relative but I still get an error: sheetal@ubuntu:~/sheetal/spec$ rspec sheetal_spec.rb \/home/sheetal/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- spec_helper (LoadError) from /home

How to expect a Params hash in RSpec in Rails 5?

别等时光非礼了梦想. 提交于 2019-12-08 19:28:13
问题 I'm upgrading to Rails 5, which has broken my RSpec even though I'm passing the data I should be. The problem is obviously here: expected: ({"name"=>"MyString"}) got: (<ActionController::Parameters {"name"=>"MyString"} permitted: true>) Which means I need to be able to fix my controller assertion so that it expects the latter. This is the line that needs changing. expect_any_instance_of(Hospital).to receive(:update).with({ "name" => "MyString" }) Probably to something like this expect_any

Error `comparison of Symbol with Module failed` after upgrading to Rspec 3

冷暖自知 提交于 2019-12-08 16:25:13
问题 I just upgraded from Rspec 2.99 to Rspec 3 and am getting the following error for some of my tests. Failure/Error: Unable to find matching line from backtrace ArgumentError: comparison of Symbol with Module failed I have the following controller test require 'spec_helper' describe PeopleController, type: :controller do subject { response } describe :index do before { get :index } it { should_not be_success } it { should have_http_status '401' } end end Any idea what might be causing the error

Test for HTTP status code in some RSpec rails request exampes, but for raised exception in others

喜欢而已 提交于 2019-12-08 14:37:54
问题 In a Rails 4.2.0 application tested with rspec-rails , I provide a JSON web API with a REST-like resource with a mandatory attribute mand_attr . I'd like to test that this API answers with HTTP code 400 ( BAD REQUEST ) when that attribute is missing from a POST request. (See second example blow.) My controller tries to cause this HTTP code by throwing an ActionController::ParameterMissing , as illustrated by the first RSpec example below. In other RSpec examples, I want raised exceptions to