rspec2

Rspec: Test rescue block

ε祈祈猫儿з 提交于 2021-01-28 18:24:05
问题 I have a block like this: begin response = Facebook.make_profile_request(params[:token]) rescue => e Airbrake.notify( :error_class => "Facebook Processing", :error_message => "Error: #{e.message}" ) flash[:notice] = "Uh oh...something went wrong. Please try again." redirect_to root_path end This is what I have so far: it "should notify Airbrake if call to FB fails" do Facebook.stub(:make_profile_request).with(fb_token).and_raise(Exception) Airbrake.should_receive(:notify) get :facebook

Rspec doesn't reload changed password attribute - why?

风格不统一 提交于 2020-01-24 13:03:33
问题 I am running Rails 3.2.1 and rails-rspec 2.8.1....When I run the test for resetting a user's password, it seems that reloading the user object doesn't load the new password attribute.... Here is the code for my test: describe "Reset password page" do let(:teacher) { FactoryGirl.create(:teacher, :email=>"jane@gmail.com")} let(:old_password) { teacher.password } before do visit reset_password_form_path fill_in "Email", with: teacher.email click_button "Reset Password" end it { should have

How to mix a module into an rspec context

时光怂恿深爱的人放手 提交于 2020-01-22 05:51:19
问题 How can I mix a module into an rspec context (aka describe ), such that the module's constants are available to the spec? module Foo FOO = 1 end describe 'constants in rspec' do include Foo p const_get(:FOO) # => 1 p FOO # uninitialized constant FOO (NameError) end That const_get can retrieve the constant when the name of the constant cannot is interesting. What's causing rspec's curious behavior? I am using MRI 1.9.1 and rspec 2.8.0. The symptoms are the same with MRI 1.8.7. 回答1: You can use

Resetting a singleton instance in Ruby

风流意气都作罢 提交于 2020-01-20 18:30:35
问题 How do I reset a singleton object in Ruby? I know that one'd never want to do this in real code but what about unit tests? Here's what I am trying to do in an RSpec test - describe MySingleton, "#not_initialised" do it "raises an exception" do expect {MySingleton.get_something}.to raise_error(RuntimeError) end end It fails because one of my previous tests initialises the singleton object. I have tried following Ian White's advice from this link which essentially monkey patches Singleton to

RSpec 2 View test to validate accessible markup?

和自甴很熟 提交于 2020-01-15 08:45:47
问题 I want to make some basic accessibility tests in RSpec (obviously, to be further validated by other tools and users later; this is to catch the low-hanging fruit like finding images w/o alt tags and such) Most of the examples have just checking content is present is similar; what I want to do is get a list of tags, and then make assertions that "all" the tags found meet certain criteria (e.g. all images have to have either an alt or a longdesc; each form input needs either a label or title,

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

╄→гoц情女王★ 提交于 2020-01-14 09:42:50
问题 I'm reading through Rails 4 in Action. I'm getting the aforementioned error while testing with Rspec and Capybara. My viewing_projects_spec.rb looks like this: require 'spec_helper' feature "Viewing projects" do scenario "Listing all projectcs" do project = FactoryGirl.create(:project, name: "TextMate 2") visit '/' click_link 'TextMate 2' expect(page.current_url).to eql(project_url(project)) end end The rest of the error says Failure/Error: expect(page.current_url).to eql(project_url(project)

How can I tell Rails to use RSpec instead of test-unit when creating a new Rails app?

我是研究僧i 提交于 2020-01-11 14:50:09
问题 I have test-unit installed and rspec installed (along with -core , -expectations , -mocks and -rails version 2.6.x). When I run the command rails new foo , it uses test-unit to generate the test stub files instead of rspec . Is there an option where I can tell rails to use rspec to generate the tests instead? 回答1: The following should work: at command line: rails new MYAPP -T # The -T option tells rails not to include Test::Unit in Gemfile: gem 'rspec-rails' at command line: bundle install

Rspec error when I run my rspec test of my controller

独自空忆成欢 提交于 2020-01-06 14:10:57
问题 I am developing a Rails v2.3 application. When I run the rspec test by execute command: rspec spec/controllers/my_controller_spec.rb I got the error message which is showing below: /.rvm/gems/ruby-1.8.7-p352@myapp/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:427:in `raise_if_rspec_1_is_loaded': (RuntimeError) ******************************************************************************** You are running rspec-2, but it seems as though rspec-1 has been loaded as well. This is likely

RSpec Rails Login Filter

限于喜欢 提交于 2020-01-04 14:14:33
问题 I recently switched started using rspec-rails(2.6.1) with my Rails(3.0.8) app. I'm used to Test::Unit, and I can't seem to get a filter working for my test methods. I like to keep things as DRY as possible, so I'd like to set up a filter that I can call on any test method that will login as an Authlogic user before the test method is called. I tried accomplishing this by using an RSpec filter in spec_helper.rb: config.before(:each, :login_as_admin => true) do post "/user_sessions/create",

RSpec Rails Login Filter

最后都变了- 提交于 2020-01-04 14:14:19
问题 I recently switched started using rspec-rails(2.6.1) with my Rails(3.0.8) app. I'm used to Test::Unit, and I can't seem to get a filter working for my test methods. I like to keep things as DRY as possible, so I'd like to set up a filter that I can call on any test method that will login as an Authlogic user before the test method is called. I tried accomplishing this by using an RSpec filter in spec_helper.rb: config.before(:each, :login_as_admin => true) do post "/user_sessions/create",