What does "rake test:functionals" do? - ruby-on-rails

I am brand new to ruby, and am starting to build a little shopping cart app, as a basic introduction. I was editing a test file, in the directory /test/functional/ but made a typo and hit enter, after typing "rake test:functionals" into the CLI.
I don't know enough about what this does, or how I can go back to where I was before. When I first tried it, everything was fine, but then when I tried to add some additional functionality it fell apart.

"rake test:functionals" is to run all your rails functional tests which are testing the rails controllers functionality.
You can look at rails guide on testing for further information, the link also explain other kind of test in rails.

Related

How to reload rails environment? Is `reload!` command depracated?

I tried to reload rails environment with the reload! command, I think it might be depracated. Does anyone know the modern way of reloading the rails environment? This book is available free for download, Im on page 79, it's Michael Hartl's "RailsSpace: Building a social networking website with ruby on rails", published in 2007, several people suggested that I give up on the book already, I just wanted to make sure it wasn't a modern way of doing things before I gave up on the book. So many experts on stackoverflow helped me get through the book already, I decided to take my chances.
Here is a link to the book: https://pdfs.semanticscholar.org/ca98/3b5098cd5957dc1842bb4bf3175406624bca.pdf?_ga=2.121598472.1814901715.1569094472-1963651489.1569094472, its one of the only FREE sources out there for building a social media website thats why I cant give up on it so easily, even though it was published in 2007 and its a bit outdated. Plus I just want to see what stackoverflow can do for me before I just give up on the book. So many experts on stackoverflow helped me make it this far, Im curious to find out if I can get through the entire book with stackoverflow. If anyone knows a better source that's free, please send me a link. Right now page 79, is the roadblock, its that reload! command that might be depracated. Maybe its an expert on stackoverflow that knows the knew command for it. If that's you please help. I already tried googling it, it took me straight here to stackoverflow lol. I decided to post a question of my own, that other guy's question doesn't seem to match mine so here I am. Please help if you can.
Within the Rails console (rails c, or more formally bundle exec bin/rails c) you should be able to run:
reload!
That reloads the active environment, specifically anything within app/ and config/routes.rb, but other things will not be reloaded until you exit and restart the console. This has always been the case.
Note that this is only within the Ruby interactive environment, as in you'll have a prompt that looks like this:
irb(main):001:0>
If you see something else you may not be in the Rails console and are trying to run the command in the wrong context. A common mistake is trying to run this in he shell itself where you'll get an error like:
-bash: reload!: command not found
One other thing you may need to do if you're having trouble getting things to load that should be there is to stop the Spring launcher, forcing it to reload:
spring stop
That kicks the Spring application preloader which can sometimes get confused about what's going on and needs a reset.

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.

What code gets run when you run "rails generate scaffold"?

My question is as simple is that: what code (in the Rails codebase) gets run when you run the rails generate scaffold command? I don't really know how I'd go about figuring that out.
(P.S. The reason I'm interested in this is because I want to track down what I believe to be an esoteric bug in Rails.)
See if this gets you on your way: https://github.com/rails/rails/search?q=scaffold&ref=cmdform

how would I go about 'starting over from scratch' with Rails tests?

I have an existing Rails app that I built using Rails 3, Mongoid/Mongodb and Devise. The app is running fine. I'd now like to add some tests to it (sure, shoulda done this in the beginning but the learning curve for just Rails was enough...).
I've used several pages to get it going, especially the Rails guide and this blog post about Mongo and Cucumber/Rspec. My concern here is that between all of the "add this to this and such file" that I've done to try and get this working (and it's not) I've made such a mess of things that it might be better to start over from scratch. With the testing portion of the app.
I thought I would just delete the spec and test directories and re-gen the tests but I can't find a command to do that (the regen).
I've built a very simple test (assert true) but I'm getting:
D:/Dev/TheApp/test/test_helper.rb:10:in `<class:TestCase>':
undefined method `fixtures' for ActiveSupport::TestCase:Class (NoMethodError)
I think the real issue here is that I'm using MongoDb and the test architecture in Rails seems to really really want to do ActiveRecord. Not sure if those two are compatible.
Is there a quick way to build a barebones test directory? My short term solution is to just roll back those directories. Hoping for a better solution.
The blank tests are really worthless. If you didn't have tests/specs of value, then just start from scratch. And if you want to start over, you should just delete them and start new.
You could treat your code as "legacy code" as defined by Michael Feathers in Working Effectively with Legacy Code -- that is, code without tests.
Take a look at this getting started with rails testing guide over at 10gen:
http://www.mongodb.org/display/DOCS/Rails+-+Getting+Started#Rails-GettingStarted-Testing

Can I somehow execute my db/seeds.rb file from my rails app?

I am building a demo, and I want to make it very easy for a non-technical person to set up and run the demo. I have built a seeds.rb file with lots of demo data in it. I want to be able to reset the rails app to a known state by providing an administrator-level action via a page link. I don't want to provide these non-tech demonstrators with a command line and rake, because they might shoot themselves in the foot.
I have looked into using load 'db/seeds.rb' within a method, but that doesn't quite do what I want. I know I am missing something, but what?
You can call Rails.application.load_seed. That's all rake db:seed does.
I prefer the classic method:
bundle exec rails db:seed
But I guess, that you can also call Rails.application.load_seed as mentioned.

Resources