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

  • SEARCH
  • Home
  • 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 4126986
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:06:17+00:00 2026-05-21T00:06:17+00:00

I’ve just finished the Rails3Tutorial book and I’m trying my first real world rails

  • 0

I’ve just finished the Rails3Tutorial book and I’m trying my first real world rails dev. (Feels like driving alone for the first time just after passing the test – scary).

Anyhoo, here’s my problem. I’d like to list the contents of a directory on a web page. Simple enough, but I have a few questions. I’m using RSpec by the way

Firstly, how do I test drive the solution? I need to mock the filesystem so I can dictate the results of Dir.entries (or similar) for the test case. I know I could write the contents of the directory in the before(:each) block and then clean up after the test but that feels clumsy. I know how to create a stub for the Dir objects and how to force the results, but how do I get that stubbed object into the controller. I want to use the mocked object during testing and the real thing for production. How do I do that?

Secondly, where should I put the code that inspects the file system. I’m not really using a database for this since I’m building info by looking at the directory. So should there be a model at all? Or should I do the heavy lifting in the controller?

I’m sure I’m staring the solution in the face, but any help you can give will help me make my first tentative steps into Rails loveliness. So thanks in advance.

  • 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-05-21T00:06:18+00:00Added an answer on May 21, 2026 at 12:06 am

    All your business logic should be in your models, or in modules in your library. Your controller should be dumb and should only pass information form the browser to your models, and then display information via views.

    In your specific case, the Dir class is what handles files inside a directory. All code that cares about how your “stuff” is stored should be in models.

    This will give you an array of file paths in this directory

    Dir.new("your_file_path").entries
    

    If you want to stub these, you’ll do something like

    directory = Dir.new("/") #obviously using *nix here
    directory.stub!(:entries).and_return(["fakefile.txt"])
    puts directory.entries
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
We're building an app, our first using Rails 3, and we're having to build
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace

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.