rspec-rails

Testing http basic authentication with Cucumber and RSpec in Rails 3.2.3

家住魔仙堡 提交于 2019-12-08 11:36:58
问题 I want to test the build-in basic http authentication mechanism in Rails 3.2.3. I have tried to test the http authentication in both RSpec and Cucumber but with a failing step in both tools. In Cucumber I get the following message on running my Feature: When I perform HTTP authentication as "admin" with "test" # features/step_definitions/web_steps.rb:1 undefined method `env' for nil:NilClass (NoMethodError) ./features/step_definitions/web_steps.rb:3:in `/^I perform HTTP authentication as "([^

RSpec doesn't load my class even though it loads in the Rails console

我与影子孤独终老i 提交于 2019-12-08 08:16:06
问题 I've got a class inside app/models/parser called data.rb with contents : class Parser::Data def method1 end end Nothing fancy at this point. I'm trying to write a test for it before implementing too much, just did default RSpec install for Rails. My RSpec file is in spec/models/parser/data_spec.rb and is very basic so far: require 'spec_helper.rb' describe Parser::Data do let(:parser) { Parser::Data.new } end When I run the test I get this error: spec/models/parser/data_spec.rb:3:in `<top

rake db:test:load, undefined method `[]' for nil:NilClass

只愿长相守 提交于 2019-12-08 07:56:24
问题 I want create test database. Development database have following settings: development: adapter: mysql2 encoding: utf8 database: c9 username: <%=ENV['C9_USER']%> host: <%=ENV['IP']%> When i run command: rake db:test:load --trace , displayed error: rake aborted! NoMethodError: undefined method `[]' for nil:NilClass /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:526:in `block (3 levels) in <top (required)>' /usr/local/rvm/gems/ruby-2.0.0

render_views returning NoMethodError

强颜欢笑 提交于 2019-12-08 04:38:31
I'm currently going through the Ruby on Rails Tutorial by Michael Hartl, and in Section 3.2.2 of the tutorial, he talks about using RSpec to test for the titles of the page. My tests (which I wrote myself, following his tutorial) kept failing the title tests (it can find the tag, but the title is always a blank string), and some searching on Google told me I needed to include the function render_views to pass the tests. My problem is that no matter what I try, RSpec returns a NoMethodError for render_views . The things I've tried: config.render_views in spec_helper.rb describe "Static Pages"

rails 4 - Could not find generator rspec:install

孤人 提交于 2019-12-08 01:01:30
问题 Im trying to install the rspec framework for TDD and BDD testing, and also the autotest gem for a continuos testing running at the same time the changes are done. I have been following all kind of tutorials, some of them here in stack overflow and others out there in the web, but i couldnt reach a solution, when executing the rails generate rspec:install it throws me an error 'Could not find generator rspec:install' . I attach the gem file here: [UPDATED] source 'https://rubygems.org' #

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

醉酒当歌 提交于 2019-12-08 00:05:20
问题 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

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

孤者浪人 提交于 2019-12-07 17:52:13
问题 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:

Testing an external API using RSpec's request specs

只愿长相守 提交于 2019-12-07 17:47:45
问题 I am trying to use RSpec's request specs to change the host to point to a remote URL instead of localhost:3000. Please let me know if this is possible. Note: Just wanted to mention that the remote URL is just a JSON API. 回答1: Yes, it's possible Basically require 'net/http' Net::HTTP.get(URI.parse('http://www.google.com')) # => Google homepage html But you may need to mock the response as tests are better not to depend on external resource. Then you can use mock gems like Fakeweb or similar:

Rails integration test against page modification hack?

六眼飞鱼酱① 提交于 2019-12-07 11:21:13
问题 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

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

允我心安 提交于 2019-12-07 10:47:11
问题 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. 回答1: 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