Tutorial by Examples

The following example uses allow and receive to stub a Cart's call to a CreditCardService so that the example doesn't have to wait for a network call or use a credit card number that the processor knows about. class Cart def check_out begin transaction_id = CreditCardService.instance...
The following example uses expect and receive to mock an Order's call to a CreditCardService, so that the test passes only if the call is made without having to actually make it. class Order def cancel CreditCardService.instance.refund transaction_id end end describe Order do des...
In greeter.rb (wherever that goes in your project): class Greeter def greet "Hello, world!" end end In spec/greeter_spec.rb: require_relative '../greeter.rb' RSpec.describe Greeter do describe '#greet' do it "says hello" do expect(Greeter.new.gr...
Clear the canvas using compositing operation. This will clear the canvas independent of transforms but is not as fast as clearRect(). ctx.globalCompositeOperation = 'copy'; anything drawn next will clear previous content.
Lazy, or irrefutable, patterns (denoted with the syntax ~pat) are patterns that always match, without even looking at the matched value. This means lazy patterns will match even bottom values. However, subsequent uses of variables bound in sub-patterns of an irrefutable pattern will force the patter...
CLISP has an integration with GNU Readline. For improvements for other implementations see: How to customize the SBCL REPL.
REST is a protocol-agnostic architecture proposed by Roy Fielding in his dissertation (chapter 5 being the presentation of REST), that generalizes the proven concept of web browsers as clients in order to decouple clients in a distributed system from servers. In order for a service or API to be RES...
The following examples use HAL to express HATEOAS, and make use of: CURIE (Compact URI): used to provide links to API documentation URI templates: URI that includes parameters that must be substituted before the URI is resolved Get blog 123 Request GET https://example.com/api/v1.2/blogs/123...
Most Common Lisp implementations will try to load an init file on startup: ImplementationInit fileSite/System Init fileABCL$HOME/.abclrcAllegro CL$HOME/.clinit.clECL$HOME/.eclrcClasp$HOME/.clasprcCLISP$HOME/.clisprc.lispClozure CLhome:ccl-init.lisp or home:ccl-init.fasl or home:.ccl-init.lispCMUCL$...
Some programmers think that it is a good idea to save space by using a null to represent an empty array or collection. While it is true that you can save a small amount of space, the flipside is that it makes your code more complicated, and more fragile. Compare these two versions of a method for ...
Common Lisp has a way to influence the compilation strategies. It makes sense to define your preferred values. Optimization values are between 0 (unimportant) and 3 (extremely important). 1 is the neutral value. It's useful to always use safe code (safety = 3) with all runtime checks enabled. Not...
All arrays implement the non-generic IList interface (and hence non-generic ICollection and IEnumerable base interfaces). More importantly, one-dimensional arrays implement the IList<> and IReadOnlyList<> generic interfaces (and their base interfaces) for the type of data that they cont...
On StackOverflow, we often see code like this in Answers: public String joinStrings(String a, String b) { if (a == null) { a = ""; } if (b == null) { b = ""; } return a + ": " + b; } Often, this is accompanied with an asse...
Rust's coherence rule requires that either the trait or the type for which you are implementing the trait must be defined in the same crate as the impl, so it is not possible to implement Serialize and Deserialize for a type in a different crate directly. The newtype pattern and Deref coercion provi...
Use vectors to calculate incremental [x,y] from [startX,startY] to [endX,endY] // dx is the total distance to move in the X direction var dx = endX - startX; // dy is the total distance to move in the Y direction var dy = endY - startY; // use a pct (percentage) to travel the total distance...
With functional testing data is often modified. This can cause subsequent runs of the test suite to fail (as the data could have changed from the original state it was in). If you have setup your data source using an ORM or framework that supports migration or seeding (like Doctrine, Propel, Larave...
Functional testing also can include testing processes that leave your environment, such as external API calls and emails. As an example, imagine you're functionally testing the registration process for your website. The final step of this process involves sending an email with an activation link. U...
HTML: <div class="container"> <div class="child"></div> </div> CSS: .container { height: 500px; width: 500px; display: flex; // Use Flexbox align-items: center; // This centers children vertically in the parent. ...
Because data is sensitive when dealt with between two threads (think concurrent read and concurrent write can conflict with one another, causing race conditions), a set of unique objects were made in order to facilitate the passing of data back and forth between threads. Any truly atomic operation c...
In features/step_definitions/documentation.rb: When /^I go to the "([^"]+)" documentation$/ do |section| path_part = case section when "Documentation" "documentation" else raise "Unknown documentation section: #{section...

Page 793 of 1336