rspec

How to use let variables in rails console?

浪尽此生 提交于 2021-02-19 04:14:58
问题 using rspec 2.6.4 rails 3.1.6 How to use let variables in rails test console? 1.9.3-p0 :032 > let(:user) { create(:user) } NoMethodError: undefined method `let' for main:Object Please advise, which library should be required here? For example: below is executed in console to use stub methods in console. require 'rspec/mocks/standalone' Is it possible, to define and call let variables in rails console? 回答1: If you are fine with let just creating globals, you can polyfill it like this: def let

how do you test that Rails mailer credentials are valid?

╄→гoц情女王★ 提交于 2021-02-17 19:46:29
问题 I've got a mailer sending through a GMail account, and I want to test that ActionMailer can actually log in to GMail's SMTP server with the credentials I've given it. What's the best way to test this? 回答1: It's not a full-stack solution, but you can check that the server authentication happens correctly by using Net::SMTP directly. The Mail gem that Rails 3 uses to send ActionMailer emails uses Mail like so (with your ActionMailer.smtp_settings): #line 96 of mail-2.2.7/lib/mail/network

How to test conditional ActiveRecord after_update callback with rspec?

寵の児 提交于 2021-02-10 05:52:10
问题 I have a conditional callback that triggers a job. If the manager changes, it should call the method class Employee < ActiveRecord::Base after_update :employee_manager_on_change, if: :employee_id_changed? def employee_manager_on_change EmployeeManagerChangedJob.perform_later(id) end end I'm having trouble to test this. I needed something like context 'when changing manager' do subject { user.manager = new_manager } it 'calls employee_manager_on_change' do expect { suject.run_callbacks :update

Rspec - Devise login_as does not work on the first test

六月ゝ 毕业季﹏ 提交于 2021-02-08 09:54:38
问题 I have a controller spec that needs a super admin to be logged in to work I followed this guide to and wrote the (paraphrased) following in my tests before(:each) do super_admin = FactoryGirl.create(:super_admin) login_as super_admin, scope: :super_admin end it "does whatever" do get :whatever expect(whatever).to eq(whatever) end it "does something else" do get :something_else expect(something_else).to (something_else) end My problem is that the login is only working for tests past the first,

Rspec - Devise login_as does not work on the first test

浪尽此生 提交于 2021-02-08 09:54:18
问题 I have a controller spec that needs a super admin to be logged in to work I followed this guide to and wrote the (paraphrased) following in my tests before(:each) do super_admin = FactoryGirl.create(:super_admin) login_as super_admin, scope: :super_admin end it "does whatever" do get :whatever expect(whatever).to eq(whatever) end it "does something else" do get :something_else expect(something_else).to (something_else) end My problem is that the login is only working for tests past the first,

mocking/stubbing a controller recaptcha method with rspec in rails

﹥>﹥吖頭↗ 提交于 2021-02-08 06:17:15
问题 I'm just learning how to use stubs and mocks and I would like to mock out the below verify_recaptcha method to test both outcomes of the condition. my controller code (DogMailsController) if verify_recaptcha(:model=>@email,:message=>"Verification code is wrong", :attribute=>"verification code") if DogMail.make_mail dog_mail_params result = "success" else result = "fail" end else flash.delete(:recaptcha_error) flash.now[:error] = "Validation Failed. Please enter validation numbers/letters

Rspec: testing a rescue

一个人想着一个人 提交于 2021-02-07 20:17:44
问题 Trying to test that my function will properly rescue from an exception, change the parameters (filename), and try again one time. I can get the function to receive the first try, but can't get it to receive the 2nd attempt. Controller begin @video = get_video(video_id) rescue matches = video_id.match(/(.*)[-](\d+)+x(\d+)_(\d+)/) swapped_dash = (matches && matches.size == 5) ? "#{matches[1]}_#{matches[2]}x#{matches[3]}_#{matches[4]}" : nil @video = swapped_dash.nil? ? false : get_video(swapped

How to get current context name of rspec?

╄→尐↘猪︶ㄣ 提交于 2021-02-07 11:17:44
问题 if i have rspec like this describe 'Foo' do // init go here describe 'Sub-Foo' do it "should Bar" do // test go here // puts ... <-- need "Foo.Sub-Foo should Bar" here end end end How can i get "Foo.Sub-Foo should Bar" inside the test context at // test go here? It is similar to format with specdocs, but how to get it inside itself? 回答1: describe 'Foo' do describe 'Sub-Foo' do it "should Bar" do |example| puts "#{self.class.description} #{example.description}" end end end The above code

How to get current context name of rspec?

穿精又带淫゛_ 提交于 2021-02-07 11:17:16
问题 if i have rspec like this describe 'Foo' do // init go here describe 'Sub-Foo' do it "should Bar" do // test go here // puts ... <-- need "Foo.Sub-Foo should Bar" here end end end How can i get "Foo.Sub-Foo should Bar" inside the test context at // test go here? It is similar to format with specdocs, but how to get it inside itself? 回答1: describe 'Foo' do describe 'Sub-Foo' do it "should Bar" do |example| puts "#{self.class.description} #{example.description}" end end end The above code

How to debug ruby tests in Eclipse/Aptana Studio?

旧城冷巷雨未停 提交于 2021-02-07 08:57:25
问题 is there a way to debug all/single tests in Aptana Studio / Eclipse? ruby-debug19 & ruby-debug-ide are installed and I'm able to set breakpoints and debug my development environment, e.g. in a controller's index method. If I go to http://localhost:3000/controler_name eclipse opens debugging perspective and halts. But how to do that with tests / rspec tests? Thanks in advance. 回答1: For a normal ruby file, right click on it and select Debug As > Ruby application . If your test is a rails one