rspec-rails

Unable to setup Rspec & Capybara in Rails 3.2

人盡茶涼 提交于 2019-12-01 03:07:56
问题 I am creating a sample application for rspec testing, and I followed the below steps In Gemfile: gem "rspec-rails", :group => [:test, :development] group :test do gem "factory_girl_rails" gem "capybara" gem "guard-rspec" end Then executed the below steps: bundle. rails g rspec:install. mkdir spec/support spec/models spec/routing. Added "require capybara/rspec" to my spec_helper file Created a sample test as below: require 'spec_helper' describe "Users" do describe " List users" do it "List

How to complete the rspec put controller test from scaffold

蓝咒 提交于 2019-11-30 11:41:50
问题 I'm using scaffolding to generate rspec controller tests. By default, it creates the test as: let(:valid_attributes) { skip("Add a hash of attributes valid for your model") } describe "PUT update" do describe "with valid params" do let(:new_attributes) { skip("Add a hash of attributes valid for your model") } it "updates the requested doctor" do company = Company.create! valid_attributes put :update, {:id => company.to_param, :company => new_attributes}, valid_session company.reload skip("Add

RSpec: describe, context, feature, scenario?

落爺英雄遲暮 提交于 2019-11-30 10:15:11
问题 describe , context , feature , scenario : What is the difference(s) among the four and when do I use each one? 回答1: The context is an alias for describe , so they are functionally equivalent. You can use them interchangeably, the only difference is how your spec file reads. There is no difference in test output for example. The RSpec book says: "We tend to use describe() for things and context() for context". Personally I like to use describe , but I can see why people prefer context .

alias 'it' in rspec

左心房为你撑大大i 提交于 2019-11-30 08:58:37
I'm trying to write some tests (not for code coverage, but irrelevant here) in rspec for a ROR app and need to alias describe and it, at the least. I can alias describe just fine because it's at the top level. But, I can't get anything else to work. like this guy: module RSpec module Core class ExampleGroupMethods alias :they :it end end end I included that in the spec file but I am not getting the module path right. I looked over the rspec codebase but am hitting a wall so I don't think I quite know what I'm doing. Any tips or resources would be greatly appreciated. You want to use alias

Show runtime for each rspec example

∥☆過路亽.° 提交于 2019-11-30 08:07:54
currently I'm running more than 1k examples and it's taking a long time to complete (more than 20 minutes!!! ). I'd like to identify which examples are the ones taking more time to complete, is there any way to run rspec and return the time each example takes to complete(individually)? I'm using rspec 1.3.0 and rspec-rails 1.2.3 Pan Thomakos You can use profiling to list your 10 slowest examples: spec -p spec/*/*_spec.rb --colour --format profile If you run this on a specific test suite you can get the 10 slowest examples from a smaller subset of examples: spec -p spec/models/user_spec.rb -

Unable to stub helper method with rspec

故事扮演 提交于 2019-11-30 07:24:32
问题 I am trying to stub a method on a helper that is defined in my controller. For example: class ApplicationController < ActionController::Base def current_user @current_user ||= authenticated_user_method end helper_method :current_user end module SomeHelper def do_something current_user.call_a_method end end In my Rspec: describe SomeHelper it "why cant i stub a helper method?!" do helper.stub!(:current_user).and_return(@user) helper.respond_to?(:current_user).should be_true # Fails helper.do

How to test attr_accessible fields in RSpec

不想你离开。 提交于 2019-11-30 03:03:06
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} should be accessible" } failure_message_for_should_not { ":#{attribute} should not be accessible" } end But

Rspec Rails 3.1 Integration test. How to send post request headers for mobile, http basic authentication and JSON?

霸气de小男生 提交于 2019-11-30 01:30:45
问题 I have an RSPEC integration test for a Rails 3.1 app that needs to test an api for a mobile client by issuing a POST request with JSON params and a mobile header that needs to use http_basic authentication As the request object is not available in an integration test I'm kinda stuck This is the code I have so far it "successfully posts scores" do # request.env["HTTP_ACCEPT"] = "application/json" #This causes an error as request is nly available in controller tests post "scores", :score => {

Rails 3.1 plugin gem, dummy test app, rspec

扶醉桌前 提交于 2019-11-29 18:57:18
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 your tests are still in my_gem/test , the tests dont' live in the dummy app. And my_gem/test/test_helper

alias 'it' in rspec

别来无恙 提交于 2019-11-29 12:54:05
问题 I'm trying to write some tests (not for code coverage, but irrelevant here) in rspec for a ROR app and need to alias describe and it, at the least. I can alias describe just fine because it's at the top level. But, I can't get anything else to work. like this guy: module RSpec module Core class ExampleGroupMethods alias :they :it end end end I included that in the spec file but I am not getting the module path right. I looked over the rspec codebase but am hitting a wall so I don't think I