If you test the RESTful service by hand, it will be very tedious. Of course, there are some browser plug-ins that can help you manually test by using a visual interface, such as postman, rest console, but every time a system version is updated, you need to perform a lot of tests manually, which is obviously not very practical. Ruby has a lot of excellent gem packages, and you can use them to do the boring work. One of the restclient is one I like bett
Rspec-rails Installing dependent libraries
> VI gemfile:
Gem ' Rspec-rails '
The wording of the specification:
Group:d evelopment,: Test do
...
Gem ' rspec-rails ' ...
End
> bundler Install:
Using Rspec-support 3.5.0
using Rspec-core 3.5.1 using
It would be a tedious task if you were to test restful services by hand. Of course, there are some browser plugins that can help you with manual testing through a visual interface, such as postman, rest console, but every time the system version is updated, you need to perform a lot of manual testing, which is obviously not very practical. Ruby has a lot of great gem packs that you can use to do this boring work. Restclient is one of my favorite. The
This is a concise rspec guide written by David chelimsky. The original Article is here.
Introduction
To understand rspec, we need to first understand what is behaviour driven development (BDD), and BDD is an acceptance test driven planning ), domain driven design and agile development model of test driven development (TDD. Rspec provides TDD support for BDD dev
Transfer from Http://lmws.net/describe-vs-context-in-rspecLearn RSpec, not quite understand describe and context. Google a bit, find this article, feel that there is some truth1 in the RSpec world, we often see people using Descirbe code blocks and context code blocks such as1 " launch the Rocket " Do 2 " all ready " Do 3 End 4 5 " not ready " Do 6 End7 EndSo what's the difference between cont
Test Your app's interactions with non-human users, covering external API7.1request Test vs feature Testthe RSpec , this is specifically aimed at API test is best placed in the spec/requests in the catalog, separate from the functional tests written earlier. This test is also not used Capy-bara , because it simulates browser interaction, not program interaction. We're going to use a response from the previous test controller. HTTP verb: Get , Post , De
block for deferred execution, and the detected value is executed two times before and after the request is executed to verify the change (3) Test patch request (UPDATE): The parameter is divided into legal and illegal cases, respectively verify whether the return data, and whether the success of the modification, as well as the rendering template; (4) Test delete request (destroy): Change (Class,: Count). by ( -1), redirect_to (5) Test non-crud action: There is a return value to verify the retu
If cocould not find table appears when running rspec, you need rake DB: Test: Prepare.
If your database uses sqlite3, the database used during the test is not development. sqlite3, but test. sqlite3, depending on the execution process:
Rake DB: Test: Prepare -- Trace** Invoke DB: Test: Prepare (first_time)** Invoke DB: abort_if_pending_migrations (first_time)** Invoke environment (first_time)** Execute Environment** Invoke DB: load_config (first_tim
detail inside. The big detail I'm talking about is the rails.The goal of our initial learning of Ruby was to master rails, so the subconscious, Ruby's learning was put in second place, and rails became the first learning goal.After you've read through a variety of reference books, you may be able to develop a simple Web site or apply your rails skills to a general job, but you'll find that you end up with a learning bottleneck. One of the benefits of
).2. Association of Rails. The most convenient 1-to-1, 1-to-many, many-to-many magic for wrap objects. Many other languages should not have this concept. There is an official document on Rails that is highly recommended for in-depth understanding. It is also one of the most commonly used magic to see.3. Some jobs in Rails need to be records and processed in the database that meet certain conditions. Rails often have find, find each, and find in batch, and so on, although different query statemen
).2. Association of Rails. The most convenient 1-to-1, 1-to-many, many-to-many magic for wrap objects. Many other languages should not have this concept. There is an official document on Rails that is highly recommended for in-depth understanding. It is also one of the most commonly used magic to see.3. Some jobs in Rails need to be records and processed in the database that meet certain conditions. Rails often have find, find each, and find in batch, and so on, although different query statemen
Tutorial on efficient unit tests on Ruby on Rails, rubyrails
In the system developed by the author, a large amount of data needs to be analyzed, which not only requires accurate data analysis, but also requires a certain speed. Before writing the test code, I used several major methods to achieve this requirement. As you can imagine, the code is complex, difficult to maintain, and difficult to expand. Taking the opportunity of business adjustment, I d
some_condition
Try to use until instead of while for negative condition judgment.
# bad do_something while !some_condition # good do_something until some_condition
Use Kernel # loop and break after the loop, instead of begin/end/until or begin/end/while.
# bad begin puts val val += 1 end while val
Ignore parentheses around internal DSL method parameters (such as Rake, Rails, RSpec), methods with "keywords" in
1. Why Ruby?
Why do many Java developers focus on Ruby? Ruby is a general-purpose scripting language created in Japan 10 years ago. It is a pure object-oriented language. Unlike Java, everything in ruby is an object. Ruby syntax mainly comes from smalltalk, Python and Ada.
related repos must be cloned as a gitsubmodules:
$ git submodule update --init
The test suite can be run using (requires PHANTOMJS):
$ rake
This would command would run all RSpec and mspec examples in sequence.
Automated runs
A with Guardfile decent mappings between specs and lib/corelib/stdlib files are in place. Run to has bundle exec guard -i it started.
Mspec
Mspec tests can is run with:
$ rake mspec
Alternatively, you can jus
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.