Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8222671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:21:32+00:00 2026-06-07T14:21:32+00:00

I have two rails resources: notes & technologies. Note Model: class Note < ActiveRecord::Base

  • 0

I have two rails resources: notes & technologies.

Note Model:

class Note < ActiveRecord::Base
  belongs_to :technology
end

Tecnology Model:

class Technology < ActiveRecord::Base
  has_many :notes
end

I want to use the following Capybara steps:

Scenario: Viewing notes and their technology association
    Given there are the following notes:
      | subject              |
      | recursive functions  |
    And the note "recursive functions" has the technology "JavaScript"
    And I am on the homepage
    Then I should see "recursive functions"
    And I should see "JavaScript"

The step I use for the line:

    And the note "recursive functions" has the technology "JavaScript"

Is (I suspect the issue is in the following):

Given /^the note "(.*?)" has the technology "(.*?)"$/ do |note, tech|
  @note = Note.find_by_subject!(note)
  @note.technology = Technology.find_or_create_by_name(tech)
end

I want this to find_or_create the given Technology object’s name (name is a parameter of the Technology object) and create the association so that the note belongs to the technology.

Then, the last step:

And I should see "JavaScript"

Is to verify that note.technology.name is displaying next to each note instance on Note#index

  <% @notes.each do |note| %>
    <li>
      <%= link_to note.subject, note %> 
        <% if note.technology %>
          | Tech: <%= note.technology.name %>        
        <% end %>
    </li>
  <% end %>

When I run this Cucumber feature the steps pass until the last, And I should see “JavaScript”, with the error:

expect there to be content "JavaScript" in "Note Index Page"
recursive functions \n \n recursive functions \n \n (RSpec:Expectations::ExpectactionNotMetError
./features/step_definitions/web_steps.rb:107 in '/^(?:|I )should see "([^"]*)"$/'
features\viewing_notes.feature:20:in 'And I should see "JavsScript"'

I know that the association is working because creating this association with a form works (and displays @note.technology.name on Note#index). The issue seems to be with my step definition. Is there a better way to test this to see what’s happening? Maybe writing an Rspec spec? Thanks for taking the time to help.

(Possibly relevant:)

gem 'rails', '3.0.0'

group :test do
  gem 'rspec-rails', '2.0'
  gem 'factory_girl', '2.6.4'
end

group :cucumber do
  gem 'cucumber-rails', '1.0.6'
  gem 'capybara'
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:21:33+00:00Added an answer on June 7, 2026 at 2:21 pm

    Quick answer:

    @note.technology = Technology.find_or_create_by_name(tech)
    @note.save
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Rails 3 edge, I have set up two nested resources like this: config/routes.rb
So In my rails app I have two resources (rentals, and reservations) which belong
ruby 1.9.2p290 rails 3.1.1 Basically I have two models: CHEFS and RECIPES. class Chef
ruby 1.9.2p290 rails 3.1.1 I have two models: RECIPE and RECIPE_CATEGORY with belongs_to and
I have two models: team and project routes.rb resources :teams do resource :projects end
I am having issues with my Rails 3.1 app. I have two controllers &
We have two Rails models: Person and Administrator . We're disallowing removal of Administrator
I have two Rails 3 applications that will share portions of the same database
I am new to rails validation. I have two fields: field :feed_entitlements, :type =>
I have installed two different version of rails in same gem set. When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.