Since the Rspec command is troublesome, I tried to make it possible to execute Rspec with one Rake command

Original situation / issues

I am trying Ticket Price Modeling in Ruby. I'm writing tests in Rspec, but it's a hassle to enter the Rspec command in the terminal every time.

Purpose

I want to run Rspec easily.

What you did / results

(1) I used a library called Rake. (2) All spec files can now be executed at once simply by entering the rake command in the terminal. ③ It has become easier.

What is Rake (roughly)

You can write what you want to execute in Rakefile and easily execute the contents written in Rakefile with the rake command. You don't have to type long commands in the terminal.

The directory structure is rough, but it looks like this.

├── lib
│   ├── user.rb
│   └── ticket.rb
│
├── spec
│   ├── user_spec.rb
│   └── ticket_spec.rb
│
│ ── Rakefile * Create in step 2.

Steps to do

1. Install rake

gem install rake

2. Create a Rakefile and write the code in the Rakefile.

Rakefile


① require "rspec/core/rake_task"

##Now with just the rake command,③ can be executed.
② task :default => :spec

##When the rake command is executed, the files under the rspec directory are automatically recognized as test files and the test is executed.
③ RSpec::Core::RakeTask.new(:spec) 

(Supplemental explanation) -There is a code in here that the file under the spec directory is specified. ・ About ③, I learned the article here.

"::" is a call to a "class", "module" or "method". Or "::" identifies the location in a nested environment when resolving names. Simply put, identify the location. (It is difficult to explain the concept in an easy-to-understand manner) When calling the "RSpec" class → RSpec When calling the "Core" class or module or method in the "RSpec" class → RSpec :: Core When calling the "RakeTask" module in the "Core" module in the "RSpec" module → RSpec :: Core :: RakeTask

3. Execute rake command

If you execute the rake command in the terminal, ** _ spec.rb under the spec directory will be executed in a batch.

rake

reference

Recommended Posts

Since the Rspec command is troublesome, I tried to make it possible to execute Rspec with one Rake command
[Java] I want to make it easier because it is troublesome to input System.out.println.
I tried to make Basic authentication with Java
Make it possible to handle the camera with old notebook + Ubuntu 18.04 LTS (droidcam)
I tried to make a program that searches for the target class from the process that is overloaded with Java
Since the docker-desktop preview for m1 came out, I tried to face it with my macbook pro 15inch
Since the image of the lock screen of Windows 10 is beautiful, I wanted to make it a slide show of wallpaper
[Java 11] I tried to execute Java without compiling with javac
Make it possible to search Japanese sentences with ElasticSearch
I tried to make FizzBuzz that is uselessly flexible
I tried to investigate the mechanism of Emscripten by using it with the Sudoku solver
Since the argument of link_to is nil (null) and an unexpected link was generated, I tried to verify it
roman numerals (I tried to simplify it with hash)
Since the reading of JdbcCodeList of TERASOLUNA is slow, I tried to register multiple at once.
I tried to make an introduction to PHP + MySQL with Docker
I tried to increase the processing speed with spiritual engineering
[Rails] I tried to implement batch processing with Rake task
I tried upgrading from CentOS 6.5 to CentOS 7 with the upgrade tool
I want to pass the startup command to postgres with docker-compose.
A story that made it convenient with Kotlin that it is troublesome to execute animation continuously on Android
I tried to solve the problem of "multi-stage selection" with Ruby
Is it possible to automatically generate Getters / Setters with Java Interface?
I tried to implement the image preview function with Rails / jQuery
I tried to understand how the rails method "redirect_to" is defined
I tried to make an Android application with MVC now (Java)
I tried to check the operation of gRPC server with grpcurl
I tried to understand how the rails method "link_to" is defined
I wanted to make JavaFX programming easier with the Spring Framework
I tried to make it an arbitrary URL using routing nesting
[Java] I tried to make a maze by the digging method ♪
I tried to make Numeron which is not good in Ruby
I tried to make a group function (bulletin board) with Rails
I tried to interact with Java
I tried to explain the method
[IOS] What to do when the image is filled with one color
I tried to make an automatic backup with pleasanter + PostgreSQL + SSL + docker
[iOS] I tried to make a processing application like Instagram with Swift
[Ruby] I tried to diet the if statement code with the ternary operator
I tried to make a Web API that connects to DB with Quarkus
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
I tried to make full use of the CPU core in Ruby
I tried to visualize the access of Lambda → Athena with AWS X-Ray
Is it possible to put the library (aar) in the Android library (aar) and use it?
I tried to measure and compare the speed of GraalVM with JMH
There was not much information about the city's premium gift certificate, so I tried to make it easier to use with LINE Bot without permission.
I tried to make a web application that searches tweets with vue-word cloud and examines the tendency of what is written in the associated profile
I tried to summarize the methods used
I tried to get started with WebAssembly
I tried to implement the Iterator pattern
I tried to summarize the Stream API
What is Docker? I tried to summarize
I tried to implement ModanShogi with Kinx
If it is Ruby, it is efficient to make it a method and stock the processing.
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~
I tried to compare the infrastructure technology of engineers these days with cooking.
I tried to make a simple game with Javafx ① "Let's find happiness game" (unfinished)
I tried to get the distance from the address string to the nearest station with ruby
[Android] I tried to make a material list screen with ListView + Bottom Sheet
[Small story] I tried to make the java ArrayList a little more convenient
I wanted to start the AP server and debug with just the Maven command
When I tried to use a Wacom tablet with ubuntu 20.04, I didn't recognize it.