rspec-rails

NameError: undefined local variable or method `app'

与世无争的帅哥 提交于 2019-12-07 06:14:05
问题 The controller spec I created fails with the following error message: NameError: undefined local variable or method `app' for \ #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x00000004424880> ... # spec/controllers/sessions_conroller_spec.rb require 'spec_helper' describe SessionsController do before do @user = User.gen! end describe "#create" do context "when sending valid email and password" do it "renders a json hash ..." do post :create, email: @user.email, password: @user

Capybara::ElementNotFound: Unable to find visible field

时光怂恿深爱的人放手 提交于 2019-12-07 04:47:05
问题 Received following error for my Capybara test in terminal: Failures: 1) Users User create new user Failure/Error: fill_in 'Username', with: 'Ali', visible: false Capybara::ElementNotFound: Unable to find field "Username" that is not disabled within #<Capybara::Node::Element tag="form" path="/html/body/form"> # ./spec/features/users_spec.rb:31:in `block (4 levels) in <top (required)>' # ./spec/features/users_spec.rb:30:in `block (3 levels) in <top (required)> My test code in capybara: require

How can I specify https protocol in routing spec with rspec?

岁酱吖の 提交于 2019-12-07 03:04:07
问题 In my routes file I have: resources :subscription, :only => [:show], :constraints => {:protocol => "https"} I'm trying to add a spec for this route like this: it "recognizes and generates #show" do { :get => "/subscription", :protocol => 'https' }.should route_to(:controller => "subscriptions", :action => "show") end However, the spec still fails. If I remove the :protocol => 'https' , the spec also fails: ActionController::RoutingError: No route matches "/subscription" 回答1: The (undocumented

Rails rspec and omniauth (integration testing)

时光怂恿深爱的人放手 提交于 2019-12-06 23:39:39
问题 My Rails 3.2 app uses OmniAuth and Devise to sign in with Twitter. The authentication system works fine. I would like to write an integration test in rspec to make sure everything works. Using the information in the wiki, I've written the following, but I know I'm missing things. Under test.rb in config/environments, I have the following lines OmniAuth.config.test_mode = true OmniAuth.config.mock_auth[:twitter] = {:provider => 'twitter', :uid => '123545'} My rspec test looks like this:

I can't seem to add “config.include FactoryGirl::Syntax::Methods” to my rspec config block in spec_helper.rb

你离开我真会死。 提交于 2019-12-06 20:52:27
问题 If I add: config.include FactoryGirl::Syntax::Methods under RSpec.configure do |config| and run rspec, I see this error: /Users/perry_mac/rails_projects/mymri/spec/spec_helper.rb:21:in `block in ': uninitialized constant FactoryGirl (NameError) my gemfile.lock can be seen in this pastebin my gemfile can be seen in this pastebin If I omit the Rspec.comfigure statment, my tests all run fine. I'd like to make use of the abbreviated syntax, but am not sure what I am doing wrong here. 回答1: You

Rspec rails printing lot of warnings

痞子三分冷 提交于 2019-12-06 20:27:49
问题 I am testing a rails 4.1.0 application with rspec-rails 3.0.1. rspec command is printing a large number of warnings about the gems I am using in the application. I have included a part of the output below. I want to know whether is it possible to suppress this. /home/indika/Documents/rails/news_app/config/initializers/kramdown.rb:6: warning: method redefined; discarding old convert_img /home/indika/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/kramdown-1.4.0/lib/kramdown/converter/html.rb

Testing controllers with Minitest

独自空忆成欢 提交于 2019-12-06 20:16:23
问题 I'm trying to find examples of testing controllers with Minitest, but I've only found a couple and the just verify what template is rendered and that 'success' is returned. That doesn't seem very helpful to me. Is Minitest used to test controllers? The Railscast ( http://railscasts.com/episodes/327-minitest-with-rails ) and a couple other posts I've found seem to do model tests with Minitest and integration tests with Capybara. What about controller tests? Can they be tested with Minitest? If

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

回眸只為那壹抹淺笑 提交于 2019-12-06 16:22:34
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-p247/gems/rake-10.4.2/lib/rake/task.rb:240:in `call' /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rake-10.4

rails 4 - Could not find generator rspec:install

扶醉桌前 提交于 2019-12-06 13:42:01
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' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.0.3' # Use sqlite3 as the

RSpec: how to set a controller's instance variable

ⅰ亾dé卋堺 提交于 2019-12-06 09:15:42
问题 I have a this method in my rails controller: def some_init_func # ... @inst_var = 1 # ... end and later on: do_something_with(@inst_var) How do I set this instance variable in RSpec? allow(controller).to receive(:some_init_func) do # ???? what goes here ???? end Muchas gracias :) 回答1: assign is an RSpec method available for view tests, but it's not supported for controller tests. Controllers are typically expected to set instance variables, so RSpec doesn't allow for setting them, but it does