Switching test::unit with rspec under rails [duplicate] - ruby-on-rails

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to remove unit test and replace it with rspec?
Kinda odd question here: when you go with rpsec instead of test::unit on rails, what do you do with the test dir? Keep it (for any compatibility issues maybe?) or remove it?

I have always kept it, in case some plugin or generator expects to find it there.
If you don't like having the test directory, I suggest you try to remove it and see if it works. You can always recreate it later, if you notice that you need it.

Related

Rails test environment doesn't migrate [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Production, and development work just fine, but the test environment doesn't want to migrate.
Does anyone have any idea as to why the gem is not working for the migration?
Did you run bundle exec rspec:install ?
In case you have multiple versions of rspec, you can try bundle exec rspec so it calls the one defined in your Gemfile.
Instead of require, try require_relative, that way, the path is resolved regardless of the location from which you're calling the script.
I ended up removing the repo, and deleting my database then re-installing everything which seemed to do the trick.

How to convert rails app to test files?

I like to create rspec test from working rails 5 app.
It' could be template to work on.
For example:
-scaffold will create test files template which is nice.
-Or simplecov to help increase test ratio (if I understand correctly)
-So if any tools that could run through each line of controller method and re-create each expected/result put in the test file.
Are there any gem or solution ?
Why ask this question?.
I understand this is not a purpose of test. However test is to save time in future and now as well. Many rails app don't have test, and to go back each line of running code will cost again, assuming the app is good at this stage. If we can have all test at this point and use it to control / run for future development that would be good
I found another gem that answer my question
rspec-kickstarter
But to use with Rails 5 it need to edit the path that created.

Updating Rails version of an application [duplicate]

This question already has answers here:
How to get started on TDD with Ruby on Rails? [closed]
(7 answers)
Closed 6 years ago.
I currently work in a big Rails App that sadly has no test coverage and is currently on version 3 of Rails.
What would be the best approach in order to migrate to Rails 4 ? I know it's better to migrate step by step on Rails version, but the application is very big.
Should I invest in Tests before doing so ? What kind of tests ? Unit testing ? Integration tests ?
Our approach looked like this (and religiously followed this guide):
Make sure we have unit tests for all models/controllers
Add integration tests for all business critical paths in the app
Add the strong_params gem to the app, see what breaks, fix the broken things
In Gemfile, for each gem with version, look at gem dependencies and attempt to upgrade to latest version possible (i.e., removing warnings, update integrations, making sure tests pass)
Upgrade the rails gem -- see what breaks, fix the broken things
You'll notice that in the guide, the first thing they drill on is test coverage. It sounds like that might be the best place for you to start.
I am suggesting you to have atleast rspec unit test for all models and controllers then proceed to upgrade the application.
But without tests if you upgrade then it would be a problem to find any issues inside the application, becuse we cant predict whether it's due to upgrade or issue with the written code.
If you have very complicated views like calculations or showing some important informations then it's good to write integration test as well, else that's not a necessary.

how to generate rspec model in rails3 [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Could not find generator rspec_model issue
is there any command to generate the model for Rspec without generating any migration and fixture for rails 3, and is it possible to generate the rspec_model after building the project
with same app/model?
The only generator in the rspec-rails gem is rspec:install.
Reading: https://github.com/rspec/rspec-rails#generators
When running rspec:install, it's not going to create spec/model/... files for your existing models, but there is no proble with you running rspec:install on an existing application.
Reading: Could not find generator rspec_model issue
It's really very easy to create your own spec/model/... files; all they need is
require 'rspec_helpers'
at the top.

How to run Ruby programs in MAC OS Terminal [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to run ruby files?
I am starting to learn Ruby and having a hard time running the Ruby classes in the Terminal.
I created a class in the Sublime Text editor, just "hello world". I can compile using ruby hello.rb,
but how do I execute it?
I went to the terminal in my root directory and typed rails c which gave me a console. Could some one please tell me how to create an instance? Which console do I use?
Ruby is interpreted, so you don't need to worry about a separate compile step. ruby hello.rb is the execution command.
The standard interactive shell (REPL) is irb.
I think, this is very simple task.
Paste in terminal ruby <your script name>.rb
This is all. Ruby is interpreted lang. Compiler doesn`t exist at all. Only interpreter.
I use Ruby only few times, but I think, you must run your method hello.
Your code only create the class and nothing else.
You should firstly learn Ruby and then RoR.
As others have pointed out, running ruby hello.rb does run the script; there is no compilation involved (except behind the scenes in the Ruby virtual machine, but you don't need to concern yourself with that).
Based on the code of the file which you gave in a comment (I've put in line breaks and indentation):
class Hello
def say
puts "hello World"
end
end
... the reason your script doesn't seem to do anything is that it only defines a class and a method but doesn't instantiate the class or call the method. You had the right idea (in another comment) to call h = Hello.new(); after that you can put h.say and it will say "hello World".
(Parentheses are usually not required, including in these two method calls; but sometimes they are important. There are varying conventions, but most Rubyists skip them when calling methods without any arguments, like new and say here.)
EDIT:
rails c is for Ruby on Rails, which is a separate entity from the Ruby language (although it's written in Ruby).

Resources