rails +capybara +selenium can not open an external url - selenium

In a rails project, i add a feature file and step definition try to use capybara+selenium to load an external url,but it can not work? it has no any browser loading behavior,and from the console, it did not request the external url 'http://baidu.com' but 'http://localhost:3000' why, how can check for me,thanks very much!
**env.rb**
require 'cucumber/rails'
require 'capybara/rails'
require 'capybara/cucumber'
require 'selenium/client'
Capybara.current_driver = :selenium
Capybara.default_selector = :css
**setp_definition:**
When /^i visit baidu$/ do
visit('http://www.baidu.com/')
end
Then /^you should see Baidu$/ do
page.should have_content('Baidu')
end
****the infor on the console:****
[31m expected there to be text "Baidu" in "Browse the documentation Rails
Guides Rails API Ruby core Ruby standard library Welcome aboard You鈥檙e riding
Ruby on Rails! About your application鈥檚 environment Getting started Here鈥檚 h
ow to get rolling: Use rails generate to create your models and controllers To s
ee all available options, run it without parameters. Set up a default route and
remove public/index.html Routes are set up in config/routes.rb. Create your data
base Run rake db:create to create your database. If you're not using SQLite (the
default), edit config/database.yml
with your username and password." (RSpec::Ex
pectations::ExpectationNotMetError)[0m.

Related

How to set sinatra-authentication to use erb instead of haml?

I'm trying to set up the sinatra-authentication gem in a simple sinatra app, and running into an issue where sinatra can't find the correct views. I understand that sinatra-authentication uses haml by default, but I'm using erb in this app.
This in mind, I found in the sinatra-authenticaiton docs that there is a setting which allows you to change the template engine, by adding the following to your app file:
configure do
set :template_engine, :erb # for example
end
I've added this to my app.rb file, and sinatra is still looking for the signup.haml when I try to hit the /signup route in my app.
A couple of notes:
I've included the gem in my Gemfile, and successfuly run a bundle install on my app.
source 'https://rubygems.org'
gem 'sinatra'
gem 'data_mapper'
gem 'pg'
gem 'dm-postgres-adapter'
gem 'sinatra-authentication'
I saw something in the documentation that suggested that I may need to specify the location of my view files, so I added the following to my configuration block.
set :sinatra_authentication_view_path, Pathname(__FILE__).dirname.expand_path + "views/"
**I think I've required the gem accurately in my app file by adding
require "sinatra-authentication"
use Rack::Session::Cookie, :secret => 'mys3cr3tk3y'
This gist is a current representation of my app.rb file in the root of my sinatra app. https://gist.github.com/rriggin/5378641#file-gistfile1-txt
Here is a screenshot of the error sinatra throws: http://cl.ly/image/0y041t0K3u3O
When I run the app locally, a 'dm-users' table is created in my local db as expected.
Is there another configuration setting that I'm missing in order to get sinatra-authentication to properly look for the erb templates rather than haml files. Any help would be greatly appreciated.
Thanks
The specs don't test that the template_engine setting works, and looking at the way the setting is called, I believe it's not correct, i.e.
send settings.template_engine, get_view_as_string("index.#{settings.template_engine}"), :layout => use_layout?
might better work as:
send app.settings.template_engine, get_view_as_string("index.#{app.settings.template_engine}"), :layout => use_layout?
that's what I reckon. If you fork the project, change the line and add it to your Gemfile and it works then consider writing a quick spec for it and you'll have improved the mainline of that project as well as fixed your problem.

Rails with Jader gets 'failed to require "fs"' error

I am trying to use client side Jade templates that are precompiled by Ruby on Rails and available through JST.
I added the jader gem
gem "jader", "~> 0.0.8"
In configuration/initializers I created an initializer called jader.rb that contains:
Jader.configure do |config|
config.views_path = Rails.root.join('app','assets','javascripts','views')
config.mixins_path = Rails.root.join('app','assets','javascripts','mixins')
end
In app/assets/javascripts/views I added an index.js.jst.jade file
Hello World!
Lastly in my javascript file I have:
$('#app-content').append(JST["views/index"]());
When I run Rails and browse to the page triggering the code I am getting the following error:
failed to require "fs"
(in /my-project/app/assets/javascripts/views/index.js.jst.jade)
I understand that the problem is that jade is a node.js project and the require function is having a problem. How do I fix the require error?
If you are looking at using Jade templates only on the client side (with Rails asset pipeline), I recommend https://github.com/inossidabile/jade
It's likely there is an error in your index.jade template.
From the jade rails-fix pull request here, ExecJS used by rails does not support require("fs") and will throw 'failed to require "fs" even if it's a template error. Hopefully this should point you in the right direction.
To debug, you can replace the content of index.jade template with with a 1-liner jade placeholder to see if it renders well. Alternatively, try it out rendering the index.jade template with a nodejs server if possible to be sure the template renders without any whinning.

Cucumber: undefined method error for path on visit

I have a cucumber step
When /^I go to the Add Suggestions form$/ do
visit new_manage_suggestions_path
end
and a route
namespace "manage" do
resource :suggestions
end
rake routes outputs
manage_suggestions POST /manage suggestions(.:format) manage/suggestions#create
When I run cucumber I get
undefined method `suggestions_path' for #<#<Class:0x000000064a4768>:0x000000064accd8> (ActionView::Template::Error)
Why is cucumber trying that path?
The new_manage_suggestions_path works fine in my app, I have a link that uses it and that is working fine.
In your routes definition, in order to have your app generate the correct routes, you need to switch from the singular resource to plural resources since you could potentially have multiple suggestions.
namespace "manage" do
resources :suggestions
end
More details can be found in the Rails documentation on singular resources, where you can see that the singular version does not include the namespace in its path names.

Rails Active Admin resource problem

I recently have watched railscast 284 about active admin and wanted to implement it into my web app, however I am running into an issue when I add a resource. I get the following message every time I try to navigate to the created tab:
NameError in Admin::LoadsController#index
undefined local variable or method `per' for []:ActiveRecord::Relation
Rails.root: /Users/thomascioppettini/rails_projects/want-freight
Application Trace | Framework Trace | Full Trace
Request
Parameters:
{"order"=>"id_desc"}
Show session dump
Show env dump
Response
Headers:
None
The only thing I can think of that may affect the application is adding a recaptcha to devise, which active admin depends on.
For me, it looks like this is a pagination problem. What gem are you using? You should give as more details about your settup. Can you show us your resource file from admin directory? What version of rails and what ActiveAdmin are you using ?
If you are using the will_paginate gem, set the version to 3.0.pre2. I was using ~>3.0.pre2, which auto-updated to 3.0.2 when I ran a bundle update Reverting fixed the issue. If you're using Bundler, the line is this:
gem "will_paginate", "3.0.pre2"
I agree with Dawaid. It is a pagiantion error. Add "Kaminari" gem to you Gemfile. According to active admin docs, it is using kaminari for pagination.. will_paginate will also work for you as swilliams described...
As I understand active_admin doesn't support will_paginate anymore. But if you don't want to rewrite your pagination to Kaminari you can fix this problem with putting some code to initializers
# config/initializers/will_paginate.rb
if defined?(WillPaginate)
module WillPaginate
module ActiveRecord
module RelationMethods
alias_method :per, :per_page
alias_method :num_pages, :total_pages
end
end
end
end
module ActiveRecord
class Relation
alias_method :total_count, :count
end
end

How to access Rails 3 engine models in rails console

In the mail app's rails console (irb), how to access engine's models.
update: Say "team" is my main app and "team_page" is the engine. "team_page" is required in main app in the gemfile through 'gem => "team_page", :path => "local/path/to/team_page"'.
when I go to team's rails console, I couldn't access team_page's models.
First you must know the module's name. To help with that, you can run a
bundle show team_page
to find its directory and explore over there (probably under lib/team_page.rb) until
you see the following definition:
module TeamPage
# ...
end
Let's say that the module is called TeamPage. Then just prepend double colon to its name like this:
::TeamPage::SomeModel.some_method