I'm using rspec and selenium. Is there soemthing like a pause button I can put in my test so I can interact with the page while I'm developing a test?
Now this is not the most optimal solution, but I found it useful to throw in a breakpoint statement in the middle of the test. This allows for inspection of the document in the browser or/and values inside your code.
I use pry for the debugging and have my Rails test environment set to not cache classes. This allows for quick modifications and browser (capybara forks a separate thread) refreshes. Here is a relevant portion of my Gemfile:
group :development, :test do
gem 'rspec-rails', github: 'rspec/rspec-rails'
gem "factory_girl_rails" # factorygirl instead of fixtures
gem "guard-rspec" # automaticly running the specs when file is saved
gem 'grizzled-rails-logger', github: 'bmc/grizzled-rails-logger'
gem "faker"
end
group :test do
gem "capybara", github: 'jnicklas/capybara' # simulating a user
gem 'database_cleaner' # cleans the database
gem 'launchy'
end # remember to install rb-fsevent if your on a mac
group :epic_console do
gem 'pry' # remember to look in development.rb
gem 'pry-rails'
gem 'pry-doc'
gem 'awesome_print'
gem 'hirb'
gem 'hirb-unicode'
gem 'pry-nav'
gem 'pry-coolline'
gem 'pry-stack_explorer'
gem 'pry-exception_explorer'
end
Google the gems, see if they can optimize your process.
Related
I think I got a configuration issue with my rails setup in production.
I've got a puma working fine without any issues (connecting to db, loading models etc) and previously was able to use the console (I've encountered this [bug][https://github.com/rails/rails/issues/19256] but worked around it by filling in the database.yml)
When I try to open the console to perform little operations, none of my model classes are found.
✗ bundle exec rails console production
Running via Spring preloader in process 18313
Loading production environment (Rails 5.1.4)
irb(main):001:0> User.count
NameError: uninitialized constant User
from (irb):1
irb(main):002:0>
Similar questions on SO recommend to run ActiveRecord::Base.subclasses and eventually Rails.application.eager_load!
When I do try to run Rails.application.eager_load! I get uninitializaed constant error
irb(main):005:0> Rails.application.eager_load!
NameError: uninitialized constant ApplicationController
Did you mean? ApplicationCable
from app/controllers/accounts_controller.rb:1:in `<top (required)>'
from (irb):5
So I guess my console is now somehow lost and hasn't loaded the project source correctly.
How can I troubleshoot this situation ?
edit 2018-02-15 : I connected my workstation to the prod environment to use the console. This worked at first, the console was behaving correctly. After a couple times the same issues appeared. After doing spring stop I was able again to user my local workstation to open a console in prod.
Interesting fact : this never happens in dev environment, although spring had an app running in this environment.
It turns out spring is also running in prod, although the spring gem is only in dev group. (see below)
Gemfile
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
gem 'rails', '~> 5.1.4'
gem 'puma', '~> 3.7'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'therubyracer', platforms: :ruby
gem 'coffee-rails', '~> 4.2'
gem 'jbuilder', '~> 2.5'
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
gem 'rails-erd', require: false, group: :development
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'pry'
gem 'pry-byebug'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'devise'
gem 'devise-i18n'
gem 'cancancan', '~> 2.0'
gem 'rolify'
gem 'redis', '~> 3.2'
group :production do
gem "sidekiq"
gem "sentry-raven"
end
gem 'pg'
gem "paperclip", "~> 5.0.0"
gem 'i18n-country-translations'
gem 'rails-i18n', '~> 5.0.0'
gem 'i18n_alchemy'
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
If you deployed through Docker make sure using -ti prefix in running command like:
docker exec -ti 4d318d505e9f rails c production
I have a sinatra server, and according to the gemfile, there are different groups of gems. Specifically, there is an application group, a testing group, and a development group. How do I switch my application between these three groups? Specifically, I want to be running my server in testing mode so I can do TDD.
Here is the gemfile.
source 'https://rubygems.org'
ruby '2.0.0'
gem 'sinatra'
gem 'sinatra-contrib', require: %w(sinatra/config_file)
gem 'thin'
gem 'slim'
gem 'sinatra-assetpack'
gem 'zurb-foundation'
gem 'compass'
group :application do
# Here should be all the specifics for the application
end
group :test do
gem 'rspec'
gem 'coveralls'
gem 'capybara'
gem 'rubocop'
end
group :development do
gem 'rake'
gem 'guard', '2.2.3'
gem 'guard-rspec'
gem 'guard-rubocop'
gem 'guard-livereload'
gem 'guard-shotgun', git: 'git#github.com:rchampourlier/guard-shotgun.git', branch: 'master'
gem 'blam'
end
Gem Groups
Bundler installs by default everything. What you probably want is something like this:
$ bundle install --without test development
for your productive server, this install everything except the test & development group.
source: http://bundler.io/v1.3/groups.html
Sinatra Environment
Since you mentions sinatra explicit you maybe also interested in the sinatra config blocks
# run only in development environment
configure :development do
use Rack::Session::Pool, :key => '', :expire_after => 60 * 10
end
# run only in test environment
configure :test do
use Rack::Session::Pool, :key => 'session', :expire_after => 60 * 60
end
# run everytime
configure do
MongoMapper.database = 'food'
User.ensure_index(:username)
Product.ensure_index(:rnd)
end
You can set the different environments with RACK_ENV.
example:
RACK_ENV=test ruby mytest.rb
source: http://www.sinatrarb.com/configuration.html#built-in-settings
I am experiencing a problem with the cucumber and rspec gems bundled in a rails app.
This is what my Gemfile looks like in a new Rails 3.2.11 application with RSpec support added:
source 'https://rubygems.org'
gem 'rails', '3.2.11'
gem 'sqlite3'
gem 'jquery-rails'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
group :test do
gem 'rspec-rails'
end
After running bundle, Gemfile.lock reports that rspec 2.12.2 is being used (the latest version of the gem, as of this writing).
But I also want to use cucumber, so I run bundle update after modifying Gemfile like so:
group :test do
gem 'rspec-rails'
gem 'cucumber-rails'
end
To my surprise, the bundled rspec is now version 2.0.1, definitely NOT cool.
In fact, this was causing all kinds of errors when running specs, and it took me a while to figure out that they were old rspec errors, fixed long ago.
I can force bundler to use the latest gem:
group :test do
gem 'rspec-rails', '>= 2.12.0'
gem 'cucumber-rails'
end
but I am unhappy, because I do not understand:
if I did something wrong to begin with
if the fix I applied is going to cause other problems down the road
if there was a way to predict this behavior
Any insights?
According to https://github.com/cucumber/cucumber-rails/blob/master/cucumber-rails.gemspec#L22, cucumber-rails depends on 'rspec-rails', '~> 2.10.1' (which means >= 2.10.1 and < 2.11). If any other upstream dependency depends on a version of rspec < 2.10.1 or >= 2.11, bundler should raise an error, so I can't understand how this happened.
As an aside, you should include rspec-rails in both the :development and :test groups (per https://github.com/rspec/rspec-rails#configure).
I can no longer run cucumber in my rails 3 app. I'm not sure exactly when it broke but I did do some rspec work that required me to use the webrat gem and it was working before that.
My error is:
$ cucumber
Using the default profile...
can't activate rack (~> 1.2.1, runtime) for ["actionpack-3.0.7", "railties-3.0.7"], already activated rack-1.3.0 for ["rack-test-0.5.7", "cucumber-rails-0.4.1"] (Gem::LoadError)
Here is my Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.7'
gem 'sqlite3'
gem 'devise'
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'
gem 'cancan'
group :development, :test do
gem 'rspec-rails', '2.5.0'
gem 'rspec', '2.5.0'
gem 'webrat', ">= 0.7.2"
gem 'cucumber-rails'
gem 'capybara'
gem 'database_cleaner'
gem 'launchy'
gem 'factory_girl_rails'
gem 'spork'
end
Please let me know if I need to supply more info and I'll edit this.
I've tried specifying rack in my Gemfile but this doesn't seem to help and doesn't seem right. Also: If I modify my Gemfile I am running "bundle install" and then trying cucumber again. Is this the right workflow to solve this problem?
Can anyone please help?
Cheers,
Rim
Someone in my IRC channel pointed me in the right direction.
Use the context of bundler (which I don't quite understand yet)
bundle exec cucumber
This works just fine :)
I am trying to get cucumber to work with Rails 3.
But whenever I try to run the cucumber features I get an load error.
cucumber-0.7.3/lib/cucumber/ast/feature_element.rb:2:in `require': no such file to load -- gherkin/parser/tag_expression (LoadError)
I have added the following gems to the Gemfile
gem "rspec", '>= 2.0.0.beta.19'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails', '~> 0.1.1.rc6'
gem 'cucumber', '~> 0.7.0.beta.8'
gem 'rspec-rails', '~> 2.0.0.beta.19'
gem 'spork'
gem 'launchy'
I'm running on ruby-1.9.2-p0
Any suggestions?
I was getting the same error and was able to move past it by forcing gherkin to be loaded in Gemfile instead of as a cucumber dependency.
So, assigning specific version to Gherkin and >= to cucumbers:
...
gem 'gherkin', '2.1.5'
gem 'cucumber-rails', '>=0.3.2'
gem 'cucumber', '>=0.8.5'
...