rspec-rails

Capybara & Rspec: How to delete an account?

三世轮回 提交于 2019-12-06 08:46:31
问题 I'm using Devise and writing a test for the scenario of a user deleting their own account but I'm stuck on how I would call up the confirm box and click OK. Here is the link and my test: <p><%= link_to "Delete my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %></p> spec/requests/users_spec.rb scenario 'user deletes account' do make_user_and_login click_link('Account Settings') page.should have_selector('title', :text => 'Account

Controller test emits debug (failure) messages after Rails 5.1 upgrade

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 07:16:43
I have recently upgraded a project to Rails 5.1. All deprecation warnings were fixed. All tests pass (I use rspec-rails ) Controller tests that call mailers using ActiveJob are now rendering lengthy warning messages. [ActiveJob] [ActionMailer::DeliveryJob] [6d2ec032-eff2-40d3-bad4-3b23de65d9bd] Could not log "render_template.action_view" event. NoMethodError: undefined method 'example_group' for nil:NilClass [ "rails/view_rendering.rb:67:in 'current_example_group'", "rspec/rails/view_rendering.rb:71:in 'render_template'", "active_support/subscriber.rb:99:in 'finish'", ... LIST SHORTENED FOR

How can I stub a controller helper method in a view spec with RSpec 3.4?

时光毁灭记忆、已成空白 提交于 2019-12-06 03:31:01
I'm testing a view with RSpec (3.4 on Rails 4.2.5). And I use the decent_exposure gem in my CRUD controller. decent_exposure makes it easy to define named methods that are made available to my views and which memoize the resultant values. But I don't understand how I can stub these methods in a view spec. I tried do it according to the RSpec documentation, but it raises an error. Why doesn't it work? How can I stub the method article in the view? My controller class Account::ArticlesController < Account::BaseController expose(:articles) { current_user.articles } expose(:article, attributes:

Rails 2.3 and rspec-rails compatability

故事扮演 提交于 2019-12-06 02:58:02
问题 What version of the rspec-rails gem is still compatible with Rails 2.3 branch (2.3.14 specifically)? I've tried 2.1.0 , but that one's also for Rails >= 3.0. Any other dependencies or version limitations that I should be aware of? Thanks. 回答1: Version 1.3.4 is the latest supported version for Rails 2.x. http://rubygems.org/gems/rspec-rails/versions/1.3.4 来源: https://stackoverflow.com/questions/9274329/rails-2-3-and-rspec-rails-compatability

Cucumber and Rspec

北城以北 提交于 2019-12-06 02:53:40
问题 Can anyone suggest me good source (Easy examples) for cucumber and rspec tutorials (rails 3)??? Edit: Actually I am looking for free online resources with good examples.. 回答1: I think the RSpec Book is an excellent resource on Cucumber, RSpec and BDD. 回答2: Agree - the RSpec Book provides a wealth of information. I found getting the flow was a big problem in the learning. The book gives you the quick intro, then dives into details and by the time you surface your head will be swimming. It

Testing “Post create” with Rspec

拈花ヽ惹草 提交于 2019-12-06 00:35:14
问题 I am trying to test a "Post create" action with Rspec. The code is as follows: def valid_attributes { :zone => Flymgr::Zone.new(:countries => Flymgr::ZoneCountry.first, :name => 'USA', :description => 'USA Flight', :zipcodes => ''), :price => '100.00', :class => 'first', } end def valid_session {} end before(:each) do @request.env["devise.mapping"] = Devise.mappings[:admin] admin = FactoryGirl.create(:admin) sign_in admin end describe "POST create" do describe "with valid params" do it

Mocking chain of methods in rspec

≡放荡痞女 提交于 2019-12-05 22:02:22
问题 There are a chain of methods which gets a user object. I am trying to mock the following to return a user in my Factory Girl @current_user = AuthorizeApiRequest.call(request.headers).result I can mock the object up until the call method but I'm stuck at mocking the result method allow(AuthorizeApiRequest).to receive(:call).and_return(:user) 回答1: I found I need to use receive_message_chain So this worked for me. allow(AuthorizeApiRequest).to receive_message_chain(:call, :result).and_return

Is there any difference between a feature spec and a view spec?

↘锁芯ラ 提交于 2019-12-05 19:05:32
I had a question about within dryness in Capybara here . Tom answered perfectly and in his answer he mentioned: Feature tests should be for testing larger behaviours in the system. Is there a difference between a feature spec and a view spec in Ruby on Rails? If possible explain it with some example please. Thank you. Yes, feature and view specs are quite different. The first is a full integration test and the second tests a view in isolation. A feature spec uses a headless browser to test the entire system from the outside just like a user uses it. It exercises code, database, views and

How to test strong params with Rspec?

放肆的年华 提交于 2019-12-05 14:17:32
问题 What is the actual strategy to test strong params filtering in Rails controller with Rspec? (Except shoulda matchers) How to write failing test and then make it green? 回答1: Create 2 hashes with expected and all (with unsatisfied) parameters. Then pass all params to action and check that you object model receiving only expected params. It will not if you are not using strong parameter filters. Than add permissions to params and check test again. For example, this: # action def create User

Rails integration test against page modification hack?

一曲冷凌霜 提交于 2019-12-05 12:13:16
I'm using Capybara 1.1.2, Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0. Assume an app with standard and account_admin users. A standard user can create another standard user, but a standard user cannot create an account_admin user. Of course the UI does not give the standard user the option of creating an account admin. But 30 seconds with Firebug and the user can re-write the HTML so it submits a POST request to create an account_admin. How do I test that my app prevents this kind of simple hack? The normal standard user test looks like this: context "when standard user is signed in" do