During debugging you might pepper your code with lines like these: console.log('foo = ' + foo + ', bar = ' + bar) I recommend to use variable interpolation instead: console.log('foo = %o, bar = %o', foo, bar...
...look at its contents Another concise way to write the statement is this: console.log({ foo, bar }); This uses Javascript's new destructuring syntax and is actually shorthand for: console.log({ foo...
include_hash Matches if the given hash is included in the receiving hash: { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a') # passes { :foo => 'a', :bar => 'b' }.should include...
...hash(:foo => 'b') # fails { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a', :baz => 'c') # fails
...to be able to say this? When I go to the user form for "foo@bar.de" # goes to edit_user_path(User.find_by_anything!('foo@bar.de')) When I go to the form...
...for the user "foo@bar.de" # goes to edit_user_path(User.find_by_anything!('foo@bar.de')) When I go to the form for the user above" # goes to edit_user_path(User.last)
...x you might instead want to use an older cheat sheet. Expectations # RSpec expect(foo).to.eq("value") expect(foo).to_not eq("value") # Jasmine expect(foo).toBe("value")
...not.toBe("value") Mocks # RSpec expect(foo).to_receive(:method).twice.with('arg').and_return('value') # Jasmine spyOn(foo, 'method').and.returnValue('value') expect(foo.calls.count()).toBe(2) expect(foo.method).toHaveBeenCalledWith('arg...
...Here is a useless comment. -# It will be removed. class File1 - def foo + def bar # ... end end diff --git a/file2.rb b/file2.rb index 550e1c6..600f4e3 100644 --- a/file2.rb +++ b/file2.rb...
...Here is another useless comment. class File2 - def foo + def bar # ... end end While you can easily stage such changes using git add -p, you can be much faster when...
...computed property name in square brackets. We may now use Account instances with up.util.isBlank(): foo = new Account('foo@foo.com') bar = new Account('') console.log(up.util.isBlank(foo)) // prints false console.log(up.util.isBlank(bar)) // prints...
...to be more precise, it inherits from Hash): errors = ActiveModel::Errors.new(Object.new) => {} >> ?> errors.add(:base, "foo") => ["foo"] >> errors.add(:base, "bar") => ["foo", "bar"] >> ?> errors => {:base=>["foo", "bar"]} If you need to hack...
...the errors it will decompose arrays. For attributes with multiple errors such as :base => ["foo", "bar"] it yields once per value ("foo" and "bar" here) within the array and not...
Our preferred syntax prefixes the issue title with its ID in brackets, e.g. [FOO-123] Avatars for users. Here is how to generate that from an issue in Linear...
...be fixed with the :prefix-option: class Form state_machine :first_wizard_stage, prefix: :foo do state :completed end state_machine :second_wizard_stage, prefix: :bar do state :completed
This defines the following: constants: Form::STATE_FOO_COMPLETED and Form::STATE_BAR_COMPLETE instance methods: #foo_completed? and #bar_completed? Fix bug where additional inclusions of RailsStateMachine::Model...
uri = URI('http://example.com/?foo=1&bar=2') stub_request(:get, 'example.com').with(query: {foo: 1, bar: 2}) Net::HTTP.get(uri) # ===> Success If you only want to check if foo...
uri = URI('http://example.com/?foo=1&bar=2') stub_request(:get, 'example.com').with(query: hash_including(foo: 1)) Net::HTTP.get(uri) # ===> Error hash_including doesn't parse query values to string, you...
errors.add_to_base('failed') if bad_things? end end ^ # app/models/foo.rb require 'user' class Foo # something happens here end Now, when your environment is booted, Rails will automatically load your...
...models, like User. In our example, when Foo gets loaded, it will require the User class itself again. Since Ruby 1.8 identifies required files by the string you used (as...
We can call the method we're overriding inside our monkey patch: class Foo def bar(argument) 'Hello' + argument end end module FooExtensions def bar super(' in my') + ' World...
end class Foo prepend FooExtensions # the only change to above: prepend instead of include end Foo.new.bar # => 'Hello in my World' As mentioned, monkey patches are usually a threat to...
...try not to throw synchronous exceptions when encountering fatal errors. So avoid this: function foo(x) { if (!x) { throw "No x given" } else return new Promise(function(resolve, reject) { ... }); } }
...s hard to handle errors when calling foo, since we need to handle both a synchronous throw and an asynchronous rejection. Look how much code we need to handle failures...
...using the json gem, you might run into this error when using JSON.parse: >> json = 'foo'.to_json >> JSON.parse(json) JSON::ParserError: 757: unexpected token at '"foo"' from /.../gems/json-1.7.7/lib/json/common.rb:155:in...
...fix that, use a valid object to build JSON from, e.g. an array: >> JSON.parse([ 'foo' ].to_json).first => "foo" When you do that, remember to select the record from the...
In Rubocop you might notice the cop Style/CaseEquality for e.g. this example: def foo(expected, actual) expected === actual end In case expected is a Regex, it suggests to change it...
...to the following pattern: def foo(expected, actual) expected.match?(actual) end In case expected is a Regex or a String, you need to keep ===. Otherwise the actual expression is always...
Consider this class: class Foo private def test puts "Hello" end end While you can say create a block to call that method (using ampersand and colon) on Ruby...
...Foo.new.tap(&:test) Hello => # ... you cannot do that on Ruby 1.9 or 2.0: 1.9.3 > Foo.new.tap(&:test) NoMethodError: private method `test' called for # ^ 2.0.0 > Foo.new.tap(&:test) NoMethodError: private method `test' called for...
...virtual attributes that get and set a string array: post = Post.last puts post.tag_list # ['foo', 'bar', 'baz'] post.tag_list = ['bam'] puts post.tag_list # ['bam'] If you would like to create...
- form_for @post do |form| = form.check_box :tag_list, { :multiple => true }, 'foo', nil = form.check_box :tag_list, { :multiple => true }, 'bar', nil = form.check_box :tag_list, { :multiple => true...
With the most recent spec_candy.rb helpers you can say: User.stub_any_instance(:foo => :bar) user = User.new user.foo # => :bar RSpec 2 (Rails 3) RSpec 2 comes with this feature...
User.any_instance.stub(:foo => :bar) user = User.new user.foo # => :bar RSpec 3 RSpec Mocks 3.3: any_instance allow_any_instance_of(User).to receive(:foo).and_return(:bar) user = User.new
\di Create user that can create databases CREATE USER harry IDENTIFIED BY 'foo'; CREATE ROLE username WITH createdb LOGIN [PASSWORD 'password']; Change password of an existing user ...
You probably commonly used the :last-child CSS meta selector like so: .foo { border-bottom: 1px dashed #000; } .foo:last-child { border-bottom-width: 0; } However, this only...
...Instead, prefer using the + sibling selector. It applies to the element following the other. .foo + .foo { border-top: 1px dashed #000; } Note how we now use a top border instead...
...branch means switching branches. Example git checkout HEAD~2 app/models/foo.rb … drops all modifications of foo.rb and replaces the file with its version from HEAD~2 = two commits before the current...
...Ruby objects you may run into problems when encountering fields with NULL values: SELECT foo, bar, foo - bar AS baz FROM plop; +-----+------+------+ | foo | bar | baz | +-----+------+------+ | 30 | 20 | 10 |
...selected value if present and a given alternative if it would select NULL: SELECT foo, bar, foo - IFNULL(bar, 0) AS baz FROM plop; +-----+------+-----+ | foo | bar | baz...
`role_list_from': unknown role `something' (ArgumentError) Consider this task definition: namespace :foo do task :bar, :roles => :something do # do crazy stuff end end Whenever we call foo.bar...
...that is only available for that group of servers, you'll get another error: `foo.bar' is only run for servers matching {:roles=>:something}, but no servers matched To properly fix...
...When I go to the start page Then I should not see "Home of Foo" When our host is "foo.example.com" And I go to the start page
...see "Home of Foo" The host will be stubbed for the remainder of one scenario and restored after each scenario (i.e. you do not need an After step to clean...