サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
Wikipedia
relishapp.com
rspec-mocks provides two methods, allow_any_instance_of and expect_any_instance_of, that will allow you to stub or mock any instance of a class. They are used in place of allow or expect: allow_any_instance_of(Widget).to receive(:name).and_return("Wibble") expect_any_instance_of(Widget).to receive(:name).and_return("Wobble") These methods add the appropriate stub or expectation to all instances of
rspec-expectations ships with a number of built-in matchers. Each matcher can be used with expect(..).to or expect(..).not_to to define positive and negative expectations respectively on an object. Most matchers can also be accessed using the (...).should and (...).should_not syntax; see using should syntax for why we recommend using expect. e.g. expect(result).to eq(3) expect(list).not_to be_empt
Use with to specify the expected arguments. A message expectation constrained by with will only be satisfied when called with matching arguments. A canned response for an allowed message will only be used when the arguments match. To match... ...use an expression like: ...which matches calls like:
Ruby exposes several different methods for handling equality: a.equal?(b) # object identity - a and b refer to the same object a.eql?(b) # object equivalence - a and b have the same value a == b # object equivalence - a and b have the same value with type conversions Note that these descriptions are guidelines but are not forced by the language. Any object can implement any of these methods with i
Use the raise_error matcher to specify that a block of code raises an error. The most basic form passes if any error is thrown: expect { raise StandardError }.to raise_error You can use raise_exception instead if you prefer that wording: expect { 3 / 0 }.to raise_exception raise_error and raise_exception are functionally interchangeable, so use the one that makes the most sense to you in any given
The match matcher calls #match on the object, passing if #match returns a truthy (not false or nil) value. Regexp and String both provide a #match method. expect("a string").to match(/str/) # passes expect("a string").to match(/foo/) # fails expect(/foo/).to match("food") # passes expect(/foo/).to match("drinks") # fails You can also use this matcher to match nested data structures when composing
Request specs provide a thin wrapper around Rails' integration tests, and are designed to drive behavior through the full stack, including routing (provided by Rails) and without stubbing (that's up to you). Request specs are marked by :type => :request or if you have set config.infer_spec_type_from_file_location! by placing them in spec/requests. With request specs, you can: specify a single requ
The rspec command comes with several options you can use to customize RSpec's behavior, including output formats, filtering examples, etc. For a full list of options, run the rspec command with the --help flag: $ rspec --help Run with ruby Generally, life is simpler if you just use the rspec command. If you must use the ruby command, however, you'll need to require rspec/autorun. You can either pa
Upgrading from rspec-rails 5.x to version 6 RSpec Rails 6 is a major version under semantic versioning, it also follows our new versioning strategy for RSpec-Rails, which is to keep in step with Rails supported versions. Thus it supports 6.1 and 7.0. There are no changes required to upgrade to RSpec Rails 6 if you are using a supported version of Rails. If you are using an older version of Rails,
RSpec supports a one-liner syntax for setting an expectation on the subject. RSpec will give the examples a doc string that is auto- generated from the matcher used in the example. This is designed specifically to help avoid duplication in situations where the doc string and the matcher used in the example mirror each other exactly. When used excessively, it can produce documentation output that d
smalruby-editorは スモウルビー:Smalruby で利用しているRubyのプログラムを作成するためのビジュアルエディタです。 Scratch のようにブロックを使ってプログラムを作成できます。それだけではなく、直接入力してプログラムを作成することもできます。 詳しくは https://github.com/smalruby/smalruby-editor をご覧ください。 また、スモウルビー:Smalruby に興味がある方は http://smalruby.jp をご覧ください。 Topics Base - 基本 Block mode Character Control Events Hardware Looks Motion Operators Ruby Ruby mode Sensing Sound Standalone
Use bypass_rescue to bypass both Rails' default handling of errors in controller actions, and any custom handling declared with a rescue_from statement. This lets you specify details of the exception being raised, regardless of how it might be handled upstream. class AccessDenied < StandardError; end class ApplicationController < ActionController::Base rescue_from AccessDenied, :with => :access_de
There are four related matchers that allow you to specify whether or not a method yields, how many times it yields, whether or not it yields with arguments, and what those arguments are. yield_control matches if the method-under-test yields, regardless of whether or not arguments are yielded. yield_with_args matches if the method-under-test yields with arguments. If arguments are provided to this
rspec-core provides the structure for RSpec code examples: RSpec.describe Account do it "has a balance of zero when first opened" do # example code goes here - for more on the # code inside the examples, see rspec-expectations # and rspec-mocks end end Issues This documentation is open source, and a work in progress. If you find it incomplete or confusing, please submit an issue, or, better yet, a
Shared examples let you describe behaviour of classes or modules. When declared, a shared group's content is stored. It is only realized in the context of another example group, which provides any context the shared group needs to run. A shared group is included in another group using any of: include_examples "name" # include the examples in the current context it_behaves_like "name" # include the
Use the --tag (or -t) option to filter the examples by tags. The tag can be a simple name or a name:value pair. In the first case, examples with :name => true will be filtered. In the second case, examples with :name => value will be filtered, where value is always a string. In both cases, name is converted to a symbol. Tags can also be used to exclude examples by adding a ~ before the tag. For ex
rspec-core provides the structure for RSpec code examples: describe Account do it "has a balance of zero when first opened" do # example code goes here - for more on the # code inside the examples, see rspec-expectations # and rspec-mocks end end Issues This documentation is open source, and a work in progress. If you find it incomplete or confusing, please submit an issue, or, better yet, a pull
Feature specs are high-level tests meant to exercise slices of functionality through an application. They should drive the application only via its external interface, usually web pages. Feature specs are marked by :type => :feature or if you have set config.infer_spec_type_from_file_location! by placing them in spec/features. Feature specs require the Capybara gem, version 2.13.0 or later. Refer
Ruby Refactoring Tool for Vim Issues If you identify any issues or specific funtionality you would like to see added, write the Cucumber feature and submit an issue or a pull request: @issue Scenario: Add a parameter to a method defined with no parameters or parentheses Given I have the following code: """ def set_name end """ When I select the method and execute: """ :RAddParameter """ And I fill
When you run rails generate rspec:install, the spec/rails_helper.rb file includes the following configuration: RSpec.configure do |config| config.use_transactional_fixtures = true end The name of this setting is a bit misleading. What it really means in Rails is "run every test method within a transaction." In the context of rspec-rails, it means "run every example within a transaction." The idea
Use any_instance.stub on a class to tell any instance of that class to return a value (or values) in response to a given message. If no instance receives the message, nothing happens. Messages can be stubbed on any class, including those in Ruby's core library. describe "any_instance.stub" do it "returns the specified value on any instance of the class" do Object.any_instance.stub(:foo).and_return
Use let to define a memoized helper method. The value will be cached across multiple calls in the same example but not across examples. Note that let is lazy-evaluated: it is not evaluated until the first time the method it defines is invoked. You can use let! to force the method's invocation before each example. By default, let is threadsafe, but you can configure it not to be by disabling config
Use shared_context to define a block that will be evaluated in the context of example groups either locally, using include_context in an example group, or globally using config.include_context. When implicitly including shared contexts via matching metadata, the normal way is to define matching metadata on an example group, in which case the context is included in the entire group. However, you al
Use the controller method to define an anonymous controller that will inherit from the described class. This is useful for specifying behavior like global error handling. To specify a different base class you can pass the class explicitly to the controller method: controller(BaseController) You can also disable base type inference, in which case anonymous controllers will inherit from ApplicationC
RSpec ships with a rake task with a number of useful options. We recommend you wrap this in a rescue clause so that you can use your Rakefile in an environment where RSpec is unavailable (for example on a production server). e.g: begin require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) rescue LoadError end
rspec-mocks helps to control the context in a code example by letting you set known return values, fake implementations of methods, and even set expectations that specific messages are received by an object. You can do these three things on test doubles that rspec-mocks creates for you on the fly, or you can do them on objects that are part of your system. Messages and Methods Message and method a
vcr Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests. Help Wanted We're looking for more maintainers. If you'd like to help maintain a well-used gem please spend some time reviewing pull requests, issues, or participating in discussions. Usage require 'rubygems' require 'test/unit' require 'vcr' VCR.configure do |config| con
Use shared_context to define a block that will be evaluated in the context of example groups either explicitly, using include_context, or implicitly by matching metdata. shared_context "shared stuff", :a => :b do before { @some_var = :some_value } def shared_method "it works" end let(:shared_let) { {'arbitrary' => 'object'} } subject do 'this is the subject' end end require "./shared_stuff.rb" des
次のページ
このページを最初にブックマークしてみませんか?
『Home - Relish』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く