ruby on rails - RSpec NoMethodError: undefined method `assign' -


I am trying to write a test for a small gem written for rail. I want to test the gem independently of a dummy app and I think this is a good learning experience for me. However, I am stuck in getting a simple test to pass due to the above error.

Indicates for my Gemfile gemspec, I started RSPC with rspec -init .

My test (to ensure that everything is properly set before it starts properly):

  RSpec.describe 'text_field', type "View, do something on this page" Assign (user, [mock_model ("user", id: 1, name: 'ashi')) stub_template 'users / _form.html.erb' = & gt; "& Lt;% = form_for @user do | f |%> gt; & lt;% = f.text_field: name '%' & gt; & lt;% end% & gt; Rendered.should = ~ / Ashley / End End  

Complete error:

  There is something on the page of text_field (failed - 1) Failures: 1; Allocated (:: users, [NoMethodError RSpec :: ExampleGroups :: TextField Definition: `# & lt Assign ':) text_field page Failure / error is something 0x007faa143e8828 & gt; # ./spec/tests/text_field_spec.rb:4: `has & lt block (2 levels); Top (required) & gt; 'Finished in 0.03812 second (loading files 0.22166 seconds) 1 For example, 1 failed failed example: rspec ./spec/tests/text_field_spec.rb:3 # text_field Top of page 1 On the slowest example Some (0.03727 seconds total time is 97.8%): The text_field page has something 0.03727 seconds ./spec/tests/text_field_spec.rb:3  

My gemspec:

  ... spec.test_files = Dir [". Spec / ** / * rb"] spec.required_ruby_version = "2.1.2" spec.add_development_dependency "bundler", "1.6.3 "Spec.add_developo pment_dependency" rails "," 4.1.4 "spec.add_development_dependency" rspec-rails "," 3.0.1 "spec.add_development_depen Dency "rspec-activemodel-mocks", "1.0.1" ...  

my spec_helper.rb:

  is required 'rspec / Active_model / mocks' RSpec.configure do | Config | Config.filter_run: Focus config.run_all_when_everything_filtered = true if config.files_to_run.one? Config.default_formatter = 'doc' end config.profile_examples = 10 config.order =: random kernel. Srand config.seed config.expect_with: rspec do | Expectations | Expectations.syntax =: Confirm end config.mock_with: rspec do | Mocks | Mocks.syntax =: Expected mocks.verify_partial_doubles = true end end  

I have specified the test type as a view because my understaing of RSpec docs provides that only available in the visuals . Have I lost a significant step somewhere, or what am I missing?

"post-text" itemprop = "text">

The answer, as Jaral says, is to put type: view in its testfile.

  Requires' spec_helper '' search / print / _asset.html. Type 'Hmmm' type: see this page displays 'property = build (asset)' to 'search / print / asset' property: asset assert_select ": match ('href',?)", "/ Asset / # {asset.property_id} "End End  

Where you can put it, it can be more selective about. It also works: it displays 'page', type: view ... end


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -