rspec

how to test html attributes with rspec?

十年热恋 提交于 2019-12-30 17:57:48
问题 the html I have is generated by ruby with: <%= link_to "change", "http://gravatar.com/emails" %> which results in: <a href="http://gravatar.com/emails">change</a> but I want to ensure that the link opens in a new tab with the target="blank" attribute the rspec test looks like: it { should have_link('change', href: 'http://gravatar.com/emails', target: '_blank') } but the test still passes when I don't have the target attribute being generated. 回答1: The following works for me with capybara 1.1

rspec + factory model testing nested attributes

最后都变了- 提交于 2019-12-30 11:53:08
问题 I have a rails4 app with rspec + factory_girl. I would like to test the validation that makes sure the product has at least one feature, competition, usecase and industry. The first 3 must belong to a product, but industry can exist on its own. I haven't tried to put industry in the test yet since I can't even make work the first 3. I tried the approach below in which I create a product factory that has product_feature, product_competition and product_usecase. For some reason it's not working

How can I mock super in ruby using rspec?

隐身守侯 提交于 2019-12-30 07:59:08
问题 I am extending an existing library by creating a child class which extends to the library class. In the child class, I was able to test most of functionality in initialize method, but was not able to mock super call. The child class looks like something like below. class Child < SomeLibrary def initialize(arg) validate_arg(arg) do_something super(arg) end def validate_arg(arg) # do the validation end def do_something @setup = true end end How can I write rspec test (with mocha) such that I

Verifying page title with rspec

一个人想着一个人 提交于 2019-12-30 06:14:06
问题 I'm running through Michael Hartl's Rails Tutorial. I'm trying to verify the title of my page. The test looks like this: it "should have the right title" do get 'home' response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Home") end The HTML head section looks like this <head> <title>Ruby on Rails Tutorial Sample App | Home</title> </head> I'm getting the following failure 1) PagesController GET 'home' should have the right title Failure/Error: response

What does Steak add beyond just using Capybara and RSpec in Rails testing?

随声附和 提交于 2019-12-30 06:10:30
问题 I'm trying to understand the need for Steak. I get that its like Cucumber, except that you can use pure ruby instead of mapping your english language specs to ruby like in Cucumber, but it says that it mainly adds a wrapper around the RSpec DSL, and lets you use that taken from: http://jeffkreeftmeijer.com/2010/steak-because-cucumber-is-for-vegetarians/ module Spec::Example::ExampleGroupMethods alias scenario example alias background before end module Spec::DSL::Main alias feature describe

Change default Capybara browser window size

筅森魡賤 提交于 2019-12-30 03:45:06
问题 So, with respect to integration testing using Capybara and RSpec, I know I can do this: page.driver.browser.manage.window.resize_to(x,y) per How to set Browser Window size in Rspec (Selenium) for specific RSpec tests, but is there a way to do this globally so that every test that is affected by media queries doesn't have to define this? 回答1: You could define that under before(:all) describe "Test" do before(:all) do ... ... page.driver.browser.manage.window.resize_to(x,y) #Mention it here end

Testing a gem that uses ActiveRecord models

雨燕双飞 提交于 2019-12-30 03:09:12
问题 I wrote a gem that imports data into your database if you pass in an ActiveRecord model. For example: importer = Importer.new(Widget) importer.import(data_source) Is there a good way to test this gem? I would somehow need to connect to a test database and create a test model. Thanks! 回答1: Mostly inspired from this post: http://blog.markstarkman.com/blog/2013/01/23/using-sqlite-to-test-active-record-models/ First, in your gemspec, you can add ActiveRecord and sqlite3 as dependencies like so:

undefined local variable or method `root_path'

泄露秘密 提交于 2019-12-30 02:43:10
问题 I have the following block of code in my rspec file located in the root of the /spec folder. require 'spec_helper' describe "home" do subject { page } before(:each) { visit root_path } describe "page" do it { should have_title('My Page')} end end When I run it I get undefined local variable or method `root_path' Which doesn't make any sense. When I followed the rails tutorial a similar set up worked just fine. Can anyone help? EDIT: My routes includes root "static#home" EDIT 2: Reopening this

Cuke4Nuke or SpecFlow?

拥有回忆 提交于 2019-12-29 11:48:11
问题 I am trying to decide if I should use Cuke4Nuke or SpecFlow. What are the pro/cons of each? Opinions on which is better and why. Thanks! 回答1: (I might be biased because I am involved with SpecFlow, but here my thoughts...) Cuke4Nuke is very close to Cucumber. This promises a lot of advantages: Compatibility Getting new features from Cucumber when Cucumber evolves (at least in theory, but language support is an example for this) Being a real part of the Cucumber community and the Cucumber

Capybara Ambiguity Resolution

北战南征 提交于 2019-12-29 11:31:51
问题 How do I resolve ambiguity in Capybara? For some reason I need links with the same values in a page but I can't create a test since I get the error Failure/Error: click_link("#tag1") Capybara::Ambiguous: Ambiguous match, found 2 elements matching link "#tag1" The reason why I can't avoid this is because of the design. I'm trying to recreate the twitter page with tweets/tags on the right and the tags on the left of the page. Therefore it will be inevitable that identical links page shows up on