Module: RSpec::Rails::Matchers

Included in:
RailsExampleGroup
Defined in:
lib/rspec/rails/matchers.rb,
lib/rspec/rails/matchers/be_a_new.rb,
lib/rspec/rails/matchers/be_valid.rb,
lib/rspec/rails/matchers/redirect_to.rb,
lib/rspec/rails/matchers/have_rendered.rb,
lib/rspec/rails/matchers/be_new_record.rb,
lib/rspec/rails/matchers/have_extension.rb,
lib/rspec/rails/matchers/routing_matchers.rb

Defined Under Namespace

Modules: HaveExtensions, RedirectTo, RenderTemplate, RoutingMatchers Classes: BeANew, BeANewRecord, BeValid

Instance Method Summary (collapse)

Instance Method Details

- (Object) be_a_new(model_class)

Passes if actual is an instance of model_class and returns false for persisted?. Typically used to specify instance variables assigned to views by controller actions

Examples:


get :new
assigns(:thing).should be_a_new(Thing)
post :create, :thing => { :name => "Illegal Value" }
assigns(:thing).should be_a_new(Thing).with(:name => nil)
73
74
75
# File 'lib/rspec/rails/matchers/be_a_new.rb', line 73
def be_a_new(model_class)
  BeANew.new(model_class)
end

- (Object) be_new_record

Passes if actual returns false for persisted?.

Examples:


get :new
assigns(:thing).should be_new_record
24
25
26
# File 'lib/rspec/rails/matchers/be_new_record.rb', line 24
def be_new_record
  BeANewRecord.new
end

- (Object) be_valid(*args)

Passes if the given model instance's valid? method is true, meaning all of the ActiveModel::Validations passed and no errors exist. If a message is not given, a default message is shown listing each error.

Examples:


thing = Thing.new
thing.should be_valid
37
38
39
# File 'lib/rspec/rails/matchers/be_valid.rb', line 37
def be_valid(*args)
  BeValid.new(*args)
end