rspec.info

...to add expectations on objects that will only be created when your code is called. If you have older rspec, you could use expect_any_instance_of, but with the...

...here is `and_wrap_original` validator = method.call(*arguments) # <- the original method (`cast`) is explicitly called expect(validator).to receive(:valid?) # <- a expectation on the then newly created object is added...

...Array: returns a new array where each object is deep_duped any other Object: calls dup, or self when frozen. If your object has instance variables that are hashes or...

...not a silver bullet and needs to be implemented properly by the object you call it on. Further Reading https://en.wikipedia.org/wiki/Object_copy#Shallow_copy https://makandracards.com/makandra/477919-using-deep_dup-for-copying-whole-hashes-and-array

...its generators with Rails::Generators.invoke ARGV.shift, ARGV. From inside a Rails generator, you may call the inherited Thor method invoke(args=[], options={}, config={}). There also is a generate method which...

...will run the generator in a subprocess. Call it with generate 'generator_name', 'command line args'. Expected (hard-coded) directory structure of a generator #{generator namespace, e.g. rails}/ #{generator name...

makandra dev

When you call a method on an object, Ruby looks for the implementation of that method. It looks in the following places and uses the first implementation it finds:

include IncludedModule prepend PrependedModule def action puts "Klass" super end end ... and we call a method like this: instance = Klass.new instance.extend(SingletonModule) instance.action Then we get an output as...

makandra dev

...files for images, fonts etc. Most applications will use a single pack (we often call it main), some applications might for example use separate frontend and backend packs.

...yarn upgrade [package] yarn upgrade [package]@[version] yarn remove [package] Under the hood, Yarn calls npm for you. Do not use the npm command yourself. Do not manipulate package.json yourself...

makandra dev
developer.mozilla.org

...to abort async code is that your function takes a AbortSignal { signal } property. The caller can use this signal to send an abort request to your function. Upon receiving the...

...countDown() abortable Here is a variant of countDown() that may be canceled by the caller before the time has elapsed: function countDown(seconds, options = {}) { return new Promise((resolve, reject) => {

...nested_form.object will be nil. The :reject_if option lambda in your accepts_nested_attributes call is defined incorrectly. Raise the attributes hash given to your :reject_if lambda to see...

...for already iterates for you. You used form.fields_for |nested_form|, but continue to call form helpers (like text_field) on the containing form instead of nested_form.

api.rubyonrails.org

...time, use travel: travel 1.day All those methods may also receive a block to call and restore time afterwards. If you don't provide a block, you must call travel...

Rails 3, 4, 5, 6 config/application.rb config/environment.rb before the initialize! call (we don't usually edit this file) The current environment, e.g. environments/production.rb Gems Vendored plugins All initializers in config/initializers...

config/environment.rb after the initialize! call (we don't usually edit this file) Your own code from app Rails 2 Code in config/preinitializer.rb (if it exists) environment.rb, code above the...

relishapp.com

When you are using lambdas in RSpec to assert certain changes of a call, you know this syntax: expect { playlist.destroy }.to change { Playlist.count }.by(-1) While you can define multiple...

...playlist.destroy } .to change { Playlist.count }.by(-1) .and not_change { Video.count } The above example will call playlist.destroy only once, but test both assertions. Note When you chain multiple Capybara matchers using...

makandra dev
unpoly.com

...property { alreadyHandled } shows if Unpoly thinks the change has already been handled (e.g. after calls to history.pushState()). Complete handling of #hash links Unpoly now handles most clicks on a link...

...are now emitted when the URL changes for any reason, including: When a script calls history.pushState() or up.history.push(). When a script calls history.replaceState() or up.history.replace(). When the user presses the...

If you already selected an element and want to get its parent, you can call find(:xpath, '..') on it. To get the grand-parent element, call find(:xpath, '../..'). Example

github.com

...studies. It is based on an article written by Stephen Curtis. Table of Contents Call Stack Primitive Types Value Types and Reference Types Implicit, Explicit, Nominal, Structuring and Duck Typing...

...Operators, Type Arrays and Array Buffers DOM and Layout Trees Factories and Classes this, call, apply and bind new, Constructor, instanceof and Instances Prototype Inheritance and Prototype Chain Object.create and...

ruby-lang.org

...is a slightly abbreviated version: What changed When the last argument of a method call is a Hash, Ruby < 3 automatically converted it to to Keyword Arguments. If you call...

...in Ruby >= 3 that accepts keyword arguments, either explicitly or via **kwargs, you cannot call it with a hash. I.e. def explicit_kwargs(x:, y:) # ... end def splat_kwargs(**kwargs...

...Support for combining structurally incompatible relations with and Pull request: Ignore joins on #and calls Alternative: Use SQL snippets When you call #where() with an SQL snippet string instead of...

...patch in routing-filter as it still expects an array of route data when calling super, but never actually calls the block that now needs to be called. Due to...

...this monkey patch.' end # We cannot prepend a custom extension module here because we call `super` in this method which should call the Rails # #find_routes-method and not the...

jetbrains.com

RubyMine has a collaboration feature called "Code With Me". Using it, you can invite someone into your local editor to work together. This is nicer to the eyes and much...

...icon once a session is running. Features See other people's cursor Follow others Call others to follow you Work in full sync Work independently, but still in the same...

class Movie < ApplicationRecord normalizes :title, with: -> { _1.strip } end Tip Normalization lambdas are not called for nil values by default. To normalize nil values, pass an apply_to_nil: true...

...class Movie < ApplicationRecord normalizes :title, with: Normalizers::StripNormalizer end The with keyword accepts any callable object that takes the attribute’s value as its only argument. To comply with this...

When you're nesting setTimeout(f, 0) calls, your browser will silently increase the delay to 5 milliseconds after the fourth level of nesting. This is called "timeout clamping" and...

...a similar note, all major browsers have implemented throttling rules for setInterval and setTimeout calls from tabs that are currently in the background. You can test it yourself by running...

docs.ruby-lang.org

...method. return accepts a value that will be the return value of the method call. Use break to quit from a block and from the method that yielded to the...

...jump out of a block and returns nil or the provided argument to the caller. break # => SyntaxError: Can't escape from eval with break example { break 'break' } # => 'break'

github.com

...before continuing - the event could prevent the default behavior. Luckily there is a concept called passive event listeners which is supported by all modern browsers. Below are the key parts...

...analysis indicates that the majority of touch event handlers on the web never actually call preventDefault(), so browsers often block scrolling unnecessarily. By marking a touch or wheel listener as...

...What happens when an error occurs? How do we get notified? Understand that each call of a cron job will boot up your Rails application and produce 100% load on...

Sidekiq jobs should never be enqueued in an after_create or after_save callback. Can you find out why? (Hint: You can find a spoiler here)

...provides a database-based model level mutex for MySQL. You use it by simply calling Lock.acquire('string to synchronize on') do # non-threadsafe code end You must make sure the...

...Only one process can enter the block using the same string, so a concurrent call to another Lock.acquire('string to synchronize on') will block, whereas Lock.acquire('some other string') will...

...it_should_act_like from our spec_candy.rb (note the /behave/act/). It allows you to call a standard shared example group with parameters. Some stupid examples follow to show how it...

it_should_act_like 'string equaling another string', :string => 'foo' end If you call it_should_act_like with a block, it will be made available as block: