rspec-rails

How to rspec mock open-uri?

和自甴很熟 提交于 2019-11-29 09:19:18
I have this simple code where I am sending http request and reading all the response. Here is my rails code open("http://stackoverflow.com/questions/ask") How can I write spec for this line of code. I dont have the option to use mocha and webmock. I can only use mocking framework of Rpsec. I have tried to use this statement OpenURI.stub!(:open_uri).should_receive(:open).with("http://stackoverflow.com/questions/ask") but i keep getting this error RSpec::Mocks::MockExpectationError: (#<RSpec::Mocks::MessageExpectation:0xd1a7914>).open("http://stackoverflow.com/questions/ask") expected: 1 time

save_and_open_page (capybara / launchy) stopped working in a project - error

╄→尐↘猪︶ㄣ 提交于 2019-11-29 08:07:01
Trying to debug a section of specs that I cannot get to work when merging Rails two projects. I have deleted my Gemfile.lock and re-installed from scratch, I have run bundle update on specific gems, and the whole lot but am getting an error when I try to use in my request spec save_and_open_page railsdev$ bin/rspec spec/requests/authentication_pages_spec.rb No DRb server is running. Running in local process instead ... /Users/rb/Repos/Genie/spec/requests/authentication_pages_spec.rb:33:in `block (3 levels) in <top (required)>': undefined local variable or method `save_and_open_page' for #

ActionMailer sending real emails in test mode! - How to turn off?

泄露秘密 提交于 2019-11-29 02:38:01
问题 Newly signed up users to my little app must be approved by the admin (me) before they can gain access to the site. I've succeeded in generating such emails in development with an after_create :send_admin_email in my user model which works great. My problem is that I'm generating multiple users during my tests (using FactoryGirl) and each test user created sends off a real email. Running my tests is like pouring molasses in January and I've got to delete hundreds of emails sent to my inbox.

How to test attr_accessible fields in RSpec

时光毁灭记忆、已成空白 提交于 2019-11-29 00:09:44
问题 So we have been setting up attr_accessible and attr_protected on many fields through out our Rails 3.2 app. For now we really don't test to ensure that these fields are protected. So I decided to google some answers and stumbled upon this solution: RSpec::Matchers.define :be_accessible do |attribute| match do |response| response.send("#{attribute}=", :foo) response.send("#{attribute}").eql? :foo end description { "be accessible :#{attribute}" } failure_message_for_should { ":#{attribute}

POSTing raw JSON data with Rails 3.2.11 and RSpec

可紊 提交于 2019-11-28 21:02:35
In order to ensure that my application is not vulnerable to this exploit , I am trying to create a controller test in RSpec to cover it. In order to do so, I need to be able to post raw JSON, but I haven't seemed to find a way to do that. In doing some research, I've determined that there at least used to be a way to do so using the RAW_POST_DATA header, but this doesn't seem to work anymore: it "should not be exploitable by using an integer token value" do request.env["CONTENT_TYPE"] = "application/json" request.env["RAW_POST_DATA"] = { token: 0 }.to_json post :reset_password end When I look

Why is my RSpec not loading Devise::Test::ControllerHelpers?

▼魔方 西西 提交于 2019-11-28 19:06:49
I'm using Rails 5, and Devise 3.5.1. Going through a nice (older) book about creating/testing an API, which uses Devise authentication. It was written before Rails 5, so I chose not to use the new api-only version. Here's my test... #/spec/controllers/api/v1/users_controller_spec.rb require 'rails_helper' describe Api::V1::UsersController, :type => :controller do before(:each) { request.headers['Accept'] = "application/vnd.marketplace.v1" } describe "GET #show" do before(:each) do @user = FactoryGirl.create :user get :show, params: {id: @user.id}, format: :json end it "returns the information

Rails 3.1 plugin gem, dummy test app, rspec

风流意气都作罢 提交于 2019-11-28 14:10:24
问题 So Rails 3.1 comes with a little-known handy "rails g plugin new" generator, which gives you a skeleton suitable for a rails gem plugin. [http://guides.rubyonrails.org/plugins.html#or-generate-a-gemified-plugin] One of the useful things this does, is set things up conveniently for testing with Test::Unit. It gives you a basic dummy Rails app that your tests can run in the context of, to test 'engine' behavior that only functions in the copy of a Rails app. (it puts it in ./test/dummy). But

Rails 3 Tutorial Chapter 11 “Validation failed: Email has already been taken” error

。_饼干妹妹 提交于 2019-11-28 07:45:36
My trouble arose in Chapter 11 of the Ruby on Rails Tutorial here . I was seeing this rspec error: Failure/Error: :user => Factory(:user, :email => Factory.next(:email))) ActiveRecord::RecordInvalid: Validation failed: Email has already been taken first in user_spec.rb then in micropost_spec.rb . It was pretty puzzling. I thought the factory statements were generating a user in a fresh testing db each time autotest ran rspec. I checked out source files from the master branch with git and tried again, but saw the same error. I therefore suspected it related to the db contents somehow and not

expected true to respond to true?

大憨熊 提交于 2019-11-28 07:08:47
I upgraded my rspec-rails to 3.0.1 and now I'm seeing this error on all of my tests Failure/Error: Sidekiq::Status::complete?(json.jid).should be_true expected true to respond to `true?` I can't find the solution nor what I'm missing. From rspec 3.0, be_true is renamed to be_truthy and be_false to be_falsey The behavior has not changed. So (nil).should be_falsey (false).should be_falsey will pass, and (anything other than nil or false).should be_truthy will also pass From the changelog 3.0.0.beta1 / 2013-11-07 Rename be_true and be_false to be_truthy and be_falsey. (Sam Phippen) To not to

Capybara tests with :js=>true… Routing Error: No route matches [GET] “/assets”

半世苍凉 提交于 2019-11-28 04:39:40
I'm getting a similar error in a number of tests when I add ":js => true" to them. eg: An error occurred in an after hook ActionController::RoutingError: No route matches [GET] "/assets" occurred at /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' I haven't been testing JavaScript-enabled stuff in my app before and have only just set up to do so by upgrading to Capybara 2 and installing Database Cleaner. config.use_transactional_fixtures = false, and I've added some before/after hooks (hooks?) to my spec