Drupal .dev database problem Drupal website unexpectingly takes all data from .dev db, thow settings point the main db. 

Is there any way to fix that?
Your settings are messed up somehow. I'd suggest looking into the multi-site capability to keep things straight.

You would create directories for live and test under /sites. Assuming example.com and test.example.com are your site:

/sites
    /example.com
        settings.php    # connection details for your live database

    /test.example.com
        settings.php    # connection details for your test database

    /example.local
        settings.php    # (optional) details for local development environment


Under this scheme, when you browse http://example.com, Drupal will look for the database settings in /sites/example.com/settings.php. When you browse http://test.example.com, Drupal will look in /sites/test.example.com/settings.php and so on.

An alternative would be to use environment variables set in you Apache or Nginx configuration. You would then use the PHP getenv() function to access the values. This approach would be a little bit harder to set up and troubleshoot.