rspec

Can I, as a human, view the RSpec rendered views, and if, so how?

守給你的承諾、 提交于 2019-12-23 07:13:16
问题 I would like to be able see the output from the path requested within one of my view specs. Rspec has access to the rendered view, but I would like access to it myself. Does anyone know how to actually view the rendered views? 回答1: You can use capybara with launchy, and then you can use capybara's save_and_open_page method. Read more details in this blog post. 回答2: Do you want to see it rendered in a browser or just HTML is fine? You should be able to access HTML in an instance variable

Can I, as a human, view the RSpec rendered views, and if, so how?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 07:10:07
问题 I would like to be able see the output from the path requested within one of my view specs. Rspec has access to the rendered view, but I would like access to it myself. Does anyone know how to actually view the rendered views? 回答1: You can use capybara with launchy, and then you can use capybara's save_and_open_page method. Read more details in this blog post. 回答2: Do you want to see it rendered in a browser or just HTML is fine? You should be able to access HTML in an instance variable

testing nested routes with rspec

喜欢而已 提交于 2019-12-23 07:01:38
问题 I'm trying to test routes with rspec. The following gives an error of "Expected block to return true value". I'm not sure what I am missing. Through a browser I can post to this url and it is successful. Any ideas? Thanks! Routes resources :forum_topics do resources :forum_sub_topics end Test: it "recognizes and generates nested #create" do { :post => "/forum_topics/1/forum_sub_topics" }.should route_to(:controller => "forum_sub_topics", :action => "create", :forum_topic_id => 1) end 回答1:

Rails mailer previews not available from spec/mailers/previews

两盒软妹~` 提交于 2019-12-23 06:59:28
问题 I would like to be able to preview my emails in the browser. I am using Rspec and have the following preview setup in spec/mailers/previews: # Preview all emails at http://localhost:3000/rails/mailers/employee_mailer class EmployeeMailerPreview < ActionMailer::Preview def welcome Notifier.welcome_email(Employee.first) end end When I try to access this I get the following error: AbstractController::ActionNotFound at /rails/mailers/employee_mailer Mailer preview 'employee_mailer' not found

Can't find element to click on using Capybara + Rails3

☆樱花仙子☆ 提交于 2019-12-23 06:48:24
问题 Background : I'm using Capybara with Rspec to test a Rails 3 app. Driver used : Selenium Problem : I can't find the "Sign in" button in order to click on from within my test. HTML code: <form accept-charset="UTF-8" action="/" class="filter_form" id="login" method="post"> <fieldset> <div class="modal-body"> <div class="clearfix login-fields"> <label for="user_email">Email</label> <div class="input login-inputs"> <input class="input-text" id="user_email" name="user[email]" placeholder="email"

FactoryGirl override attribute of associated object

て烟熏妆下的殇ゞ 提交于 2019-12-23 06:47:09
问题 This is probably silly simple but I can't find an example anywhere. I have two factories: FactoryGirl.define do factory :profile do user title "director" bio "I am very good at things" linked_in "http://my.linkedin.profile.com" website "www.mysite.com" city "London" end end FactoryGirl.define do factory :user do |u| u.first_name {Faker::Name.first_name} u.last_name {Faker::Name.last_name} company 'National Stock Exchange' u.email {Faker::Internet.email} end end What I want to do is override

Undescriptive error when running spec, occurs dependent on seed

核能气质少年 提交于 2019-12-23 05:11:45
问题 I have written a feature spec to test for correct multitenancy behaviour within my application. It signs in as two different users, creates a new Presentation by filling in a form and submitting it as each user, and confirms every time that only the tenant's own Presentations are visible to them. This spec passes fine sometimes, and sometimes doesn't. What is really confusing is the error that occurs: Failure/Error: click_button "Präsentation erstellen" TypeError: can't cast ActiveSupport:

Rspec is giving an error with my layout links from the rails tutorial: “Failure/Error: Unable to find matching line from backtrace”

独自空忆成欢 提交于 2019-12-23 04:32:29
问题 Same question, but solution did not work:, I've tried several versions of rspec: Why is Rspec saying "Failure/Error: Unable to find matching line from backtrace"? dpalacio:sample_app dpalacio$ rspec -v 2.0.0.beta.18 dpalacio:sample_app dpalacio$ rspec spec/ controllers/ factories.rb models/ requests/ spec_helper.rb dpalacio:sample_app dpalacio$ rspec spec/requests/ FFFFF Finished in 0.55501 seconds 5 examples, 5 failures 1) LayoutLinks should have a Home page at '/' Failure/Error: Unable to

Build factories for self referential associations in rails

戏子无情 提交于 2019-12-23 04:13:11
问题 I have a typical requirement, I have to address user object as follows user.referrer and user.referrers. Basically, user can refer more than one person and one person should be referred by one particular user. So I build associations as follows. They are working great. class User < ActiveRecord::Base attr_accessible :account_number, :display_name, :referrer_id has_many :referrers, :class_name => "User", :foreign_key => "referrer_id" belongs_to :referrer, :class_name => "User" end Now I would

Ruby/Rails/Rspec - ActiveRecord::AssociationTypeMismatch:

ぐ巨炮叔叔 提交于 2019-12-23 03:45:21
问题 OK, here's my rspec code ... before(:each) do @attr = { :greeting => "Lorem ipsum", :recipient => @recipient } end it "should redirect to the home page" do puts "spec: @attr = #{@attr}" puts "spec: recipient = #{@attr[:recipient]}" post :create, :card => @attr response.should redirect_to(root_path) end Now the output from this is: spec: @attr = {:greeting=>"Lorem ipsum", :recipient=>#<User id: 2, first_name: "Example", last_name: "User", email: "recipient@example.com", created_at: "2011-12-22