rspec

RSpec spec_helper access to session variable

梦想的初衷 提交于 2019-12-22 04:45:11
问题 I am new to RoR and Rspec. I am trying to write Rspec tests for a home controller with tests for login and logout etc. I want to be able to login/logout a user using methods from the spec_helper.rb However when I look at the spec_helper.rb it says it cannot find the session variable or methods like post. Why is this? Apologies if the question is a little ambiguous. I am not very sure how to frame this problem. Thanks 回答1: In RSpec, you can just use: session[:key] However I would suggest

RSpec: in-depth differences between before(:all) and before(:each)

别等时光非礼了梦想. 提交于 2019-12-22 04:42:57
问题 Ok, so I've ran into a very strange issue, directly connected with before blocks. I'm doing a integration testing via Watir and RSpec. For a simple test to check if user can perform a login I'm creating a 'user' record in the db by means of factory_girl. So I put the following code: before(:each) do @user = Factory(:user) end if "should perform a login" do # do stuff end In do stuff I call a browser and see how the user tries to login. Unfortunately, somehow he cannot do that — "Username isn

Rspec controller error expecting <“index”> but rendering with <“”>

三世轮回 提交于 2019-12-22 04:11:04
问题 New to testing, I'm struggling to get some controller tests to pass. The following controller test throws the error: expecting <"index"> but rendering with <""> I have the following in one of my controller specs: require 'spec_helper' describe NasController do render_views login_user describe "GET #nas" do it "populates an array of devices" do @location = FactoryGirl.create(:location) @location.users << @current_user @nas = FactoryGirl.create(:nas, location_id: @location.id ) get :index

How to use synchronize in Capybara exactly?

守給你的承諾、 提交于 2019-12-22 04:10:33
问题 If how to use wait_until is pretty clear (I've used the methods like this while creating tests through the native Webdriver methods), but not the new synchronize method (sorry:)). I've read the theme about why wait_until is deprecated, I've read the article about that, I've read the docs with method description and also read the code where the description present too. But I didn't find any example or tutorial how exactly to use this method. Anybody, please, provide few cases where I (and

Rspec controller error expecting <“index”> but rendering with <“”>

和自甴很熟 提交于 2019-12-22 04:10:12
问题 New to testing, I'm struggling to get some controller tests to pass. The following controller test throws the error: expecting <"index"> but rendering with <""> I have the following in one of my controller specs: require 'spec_helper' describe NasController do render_views login_user describe "GET #nas" do it "populates an array of devices" do @location = FactoryGirl.create(:location) @location.users << @current_user @nas = FactoryGirl.create(:nas, location_id: @location.id ) get :index

How to use synchronize in Capybara exactly?

丶灬走出姿态 提交于 2019-12-22 04:10:06
问题 If how to use wait_until is pretty clear (I've used the methods like this while creating tests through the native Webdriver methods), but not the new synchronize method (sorry:)). I've read the theme about why wait_until is deprecated, I've read the article about that, I've read the docs with method description and also read the code where the description present too. But I didn't find any example or tutorial how exactly to use this method. Anybody, please, provide few cases where I (and

bundle exec rspec spec/requests/static_pages_spec.rb from Hartl's tutorial isn't working

…衆ロ難τιáo~ 提交于 2019-12-22 04:03:37
问题 I'm following Michael Hartl's ruby on rails tutorial to test the sample app(3.2.1 Test-driven development), but I'm getting following error after typing bundle exec rspec spec/requests/static_pages_spec.rb /home/rahul/.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 (LoadError) from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0

Rspec rendering text

[亡魂溺海] 提交于 2019-12-22 03:57:42
问题 I have this Code if @temp_user.save sign_in(:user, @temp_user) render text: "OK" else render text: render_to_string(:partial => "errors") end and I try verify with rspec the render "OK" this is my actual spec: it "render text OK" do post :create, {:agent => valid_attributes} # response.should have_content("OK") response.should render_template(:text => "OK") end but this spec respond 0 failures always, even when I put "OKI" in place "OK" anyone have one suggestion for that? 回答1: If you are

Stub out address geocoding during RSpec unit test

有些话、适合烂在心里 提交于 2019-12-22 03:55:28
问题 I'm using the geocoder gem to add geocoding functionality to one of my Active Record model classes. This works great, but I don't actually want the geocoding to fire during unit tests. I've tried stubbing out the call to geocode by adding this to my RSpec test: before(:each) do User.stub!(:geocode).and_return([1,1]) end However, when I run my tests it still appears to be calling out to geocode. What am I doing wrong? FYI, this all works if I stub on the instance level (e.g. some_user.stub!

Stub unimplemented method in rspec

≡放荡痞女 提交于 2019-12-22 03:55:23
问题 I'm testing my module and I decided to test it versus anonymous class: subject(:klass) { Class.new { include MyModule } } MyModule uses method name inside klass . To let my specs work I need to stub this method name (which is unimplemented). So I wrote: subject { klass.new } allow(subject).to receive(:name).and_return('SOreadytohelp') } but it raises: RSpec::Mocks::MockExpectationError: #<#<Class:0x007feb67a17750>:0x007feb67c7adf8> does not implement: name from spec-support-3.3.0/lib/rspec